Bug Tracker

Opened 11 years ago

Closed 11 years ago

#10937 closed bug (invalid)

.on does not work for newly added elements

Reported by: [email protected] Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.1
Keywords: Cc:
Blocked by: Blocking:


I'm using ajax to fetch the content for a dialog I'm displaying using jquery ui. The following handler fails to attach for any of the input elements on the fetched html code:

$('input').on('click', function(){ alert('clicked!'); });

It does work, however, if using '.live'.

Example code: http://www.petkanski.com/test/jquery/on-bug/test.htm

The example code sets on() and live() hooks for the two buttons and fetches an ajax call containing them. You will see, that only one of the fetched buttons is operational. The button which was supposed to be hooked via '.on()' does not work.

Change History (1)

comment:1 Changed 11 years ago by dmethvin

Resolution: invalid
Status: newclosed

That's not how you use .on() for delegated events. Please read the documentation or ask for help on the forum.

Note: See TracTickets for help on using tickets.