Documentation for .on() method states in bold: "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()."
Is this requirement for jQuery elements to be in DOM obsolete?
It seems that .on() works just fine for registering event handlers on document fragments created using jQuery, even before they are added into DOM. Of course, event won't be fired, but the call to .on() may take place before adding elements to DOM.
http://james.padolsey.com/stuff/jQueryBookThing/
The second half of the article also mentions this: "Among other things, this means that you can safely bind event handlers during element creation, and they will be added using jQuery's robust event mechanism. "
If this can be adopted as official jQuery support, could you please update the API docs?
[edit]
The same paragraph in .on() API docs ends with: "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."
So this also implies that content must be in-DOM
Documentation for .on() method states in bold: "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()."
It seems that .on() works just fine for registering event handlers on document fragments created using jQuery, even before they are added into DOM. Of course, event won't be fired, but the call to .on() may take place before adding elements to DOM.
http://james.padolsey.com/stuff/jQueryBookThing/
The second half of the article also mentions this: "Among other things, this means that you can safely bind event handlers during element creation, and they will be added using jQuery's robust event mechanism. "
If this can be adopted as official jQuery support, could you please update the API docs?
[edit]
The same paragraph in .on() API docs ends with: "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."
So this also implies that content must be in-DOM