Modify ↓
Ticket #10937 (closed bug: invalid)
.on does not work for newly added elements
| Reported by: | nikola@… | Owned by: | |
|---|---|---|---|
| Priority: | undecided | Milestone: | None |
| Component: | unfiled | Version: | 1.7.1 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
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
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
Note: See
TracTickets for help on using
tickets.

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