Bug Tracker

Modify

Ticket #10937 (closed bug: invalid)

Opened 18 months ago

Last modified 18 months ago

.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

comment:1 Changed 18 months ago by dmethvin

  • Status changed from new to closed
  • Resolution set to invalid

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

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.