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

132
Vistas
addEventListener for click is not working
const renderNote = data => {
  const postListRef = ref(db, 'Notes/' +data.key);
  console.log(data.key)
  const newPostRef = push(postListRef);
  var status       = 'Pending'
  var title        = 'new note'
  var date         = '29-4-2022'
  var note         = 'newly added note'
  let card =
    `<div id="single-card" class="col-lg-4 col-md-3" data-id=${data.key} ><!--outer layer of single card-->
      <div class="card card-body"><!--card body-->
        
        <p class="badge" id="status" style="background-color: rgb(0, 81, 81);">${status}</p>
              
        <span class="side-stick"></span> <!--side-stick color-->

        <!-- note title -->
        <h5 class="note-title text-truncate w-75 mb-0" >${title}<i class="point fa fa-circle ml-1 font-10"></i></h5><!--fa fa-circle is for the dot dot dot(continuity)-->
        <p class="note-date font-12 text-muted mt-0">${date}</p>
              
        <!--note description-->
        <div class="note-content">
          <p class="note-inner-content text-muted" >${note}<i class="point fa fa-circle ml-1 font-10"></i></p>
        </div>
        <button class="btn btn-del">Delete${data.key}</button>
        <div id="actions" >

        </div>
              
      </div>
    </div>`    
  prod.innerHTML += card;

  const btnDelete = document.querySelector(`[data-id='${data.key}'] .btn-del`);
  console.log(btnDelete);
  btnDelete.addEventListener("click",()=>{
    console.log('deleting');
  });
}

EventListener is not working. But when I print the btnDelete(console.log(btnDelete);) it is printing correctly. But the eventlistener is not workingDoes anybody know what is wrong with the code?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Why don´t you use onclick in HTML?

<button onclick="console.log('deleting');" class="btn btn-del">Delete${data.key}</button>

You can even call a delete Function like that:

HTML:

<button onclick="deleteCard(${data.key})" class="btn btn-del">Delete${data.key}</button>

JavaScript:

function deleteCard(key) {
 console.log(`Delete Card with key: ${key}`)
}
about 4 years ago · Juan Pablo Isaza Denunciar
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