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

238
Vistas
How does the querySelector work on elements which are created dynamically
const element = document.createElement("article");
  // add classes
  element.classList.add("grocery-item");

  const attr = document.createAttribute("data-id");
  attr.value = id;
  element.setAttributeNode(attr);
  element.innerHTML = `<p class="title">${value}</p>
            <div class="btn-container">
              <button type="button" class="edit-btn"><i class="fas fa-edit"></i></button>
              <button type="button" class="delete-btn"><i class="fas fa-trash"></i></button>
            </div>`;
  // append child
  list.appendChild(element);
  // Edit Button
  const editBtn = element.querySelector(".edit-btn");

I am making a grocery list website and each item in the list like the milk and eggs come under their own article element which is being created in the javascript and I have added the code for that too. Now in the screenshot that I have posted, I have added 3 items in the grocery list, so there are 3 article elements created as per code given under which comes the edit and delete buttons. When I click on the edit button for,suppose eggs,how does it know that I have clicked on the eggs's edit button?

const editBtn = element.querySelector(".edit-btn");

This line accesses the edit button within the required article element but how does it access the required article element in the first place? There is no querySelector for selecting all the article elements in the rest of the code.

I am not entirely sure how to ask this question, so please do tell me some improvements

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