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

144
Views
JavaScript ListItem onClick issue

I'm working on a web-app in HTML and JS and I need to catch the clicks on each listItem of a list. The list is dynamically created in a for-loop as follows:

var i = document.createElement("li");
i.innerHTML = "something"
uList.appendChild(i);

How can I make listItems clickable or catch clicks on each of them separately (get the specific item clicked)? I've tried adding an eventListener on the list, and then isolate the target of the event (click). The problem is that this would count as many clicks as the size of the list.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Bind the onclick listener to the new element.

i.onclick = () => {
    console.log('hi');
};
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!