Bug Tracker

Opened 11 years ago

Closed 11 years ago

#11203 closed bug (invalid)

.on method doesn't work with ajax loaded content

Reported by: anonymous Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.1
Keywords: Cc:
Blocked by: Blocking:


e.g: $('.page_bar').on("click","a",function(){ do something.....});

It doesn't work if the content .page bar is loaded via ajax....

Change History (1)

comment:1 Changed 11 years ago by dmethvin

Resolution: invalid
Status: newclosed


Event handlers are bound only to the currently selected elements; they must exist on the page at the time your code makes the call to .on(). To ensure the elements are present and can be selected, perform event binding inside a document ready handler for elements that are in the HTML markup on the page. If new HTML is being injected into the page, select the elements and attach event handlers after the new HTML is placed into the page. Or, use delegated events to attach an event handler, as described next.

Note: See TracTickets for help on using tickets.