Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

138
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!