• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

Confusion about event handlers in jQuery

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello. I am doing online course and in the lesson we were making we were supposed to make <ul> list with <li> elements being crossed out if clicked on. Additionally you could add new <li> with input text field. So here is my code before watching the lecture:

After watching the lecture I get why we should use $('ul').on('click', 'li', function(){}) as it is more easy and robust way to keep click event handlers on <li> elements but what I don't get is why my code when adding new <li> element adds event handlers to the two last <li> elements on the list.
I'm doing laundry! Look how clean this tiny ad is:
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic