Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

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.
Whose rules are you playing by? This tiny ad doesn't respect those rules:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic