Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

162
Vistas
Bootstrap Dropdown clickable

I am setting up a Dropdown List with Bootstrap, built up with a elements. Every List item has it own id and text = name. Then i want to add an eventListener to check if the item is clicked. If so, then i want to do something and write the chosen name in the Dropdownbutton. But the problem is, every time i click any of the different options, it only gives back the latest added name in the list.


async function setOnLoad() {
  retrieveCoordinate();

  const query = new Parse.Query("User");

  try {
    const results = await query.find();

    var json = JSON.parse(JSON.stringify(results));

    for (let i = 0; i < json.length; i++) {
      let append = document.createElement("li");
      let name = json[i].username + "" + json[i].LastName;
      append.innerHTML = "<a class='dropdown-item' id='" + name + "' href='#'>" + name + "</a>";
      dropdownmenu.append(append);
      var element = document.getElementById(name);
      element.addEventListener("click", function(){ console.log(element.id); dropdownMenuButton1.innerHTML = element.id; }); 
    } 

  } catch (error) {
    console.log(`Error: ${JSON.stringify(error)}`);
  }
}```
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda