Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can bind the $.on to a parent element that will always exist in dom like this.</p> <pre><code>$(document).on('click','p#two', function() { console.log('p#two clicked'); }); </code></pre> <p><strong>Note that:</strong> you can replace <code>document</code> with any parent of the element that will always exist in dom, and the closer the parent the better.</p> <p>Check doc of <a href="http://api.jquery.com/on">$.on</a></p> <p>Live is depreciated. use $.on instead. Equivalent syntax of $.on for $.live and $.delegate</p> <pre><code>$(selector).live(events, data, handler); // jQuery 1.3+ $(document).delegate(selector, events, data, handler); // jQuery 1.4.3+ $(document).on(events, selector, data, handler); // jQuery 1.7+ </code></pre> <p>I would suggest you to use <code>$.on</code> for all event handling purposes as all other methods routes through $.on method under the hood.</p> <p>Check the definition of these functions from jQuery source v.1.7.2</p> <pre><code>bind: function( types, data, fn ) { return this.on( types, null, data, fn ); }, unbind: function( types, fn ) { return this.off( types, null, fn ); }, live: function( types, data, fn ) { jQuery( this.context ).on( types, this.selector, data, fn ); return this; }, die: function( types, fn ) { jQuery( this.context ).off( types, this.selector || "**", fn ); return this; }, delegate: function( selector, types, data, fn ) { return this.on( types, selector, data, fn ); }, undelegate: function( selector, types, fn ) { // ( namespace ) or ( selector, types [, fn] ) return arguments.length == 1? this.off( selector, "**" ) : this.off( types, selector, fn ); } </code></pre> <p>You can see all methods are using <code>$.on</code> and <code>$.off</code> themselves. So using <code>$.on</code> you can at least save a function call though which isn't that significant most of the cases.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload