javascript - is jquery on() always better than bind() -


this question has answer here:

i've read posts of live() versus delegate() versus on(), , understand position.

i understand how click() shortcut on(), , how 2 statements identical.

$( "#clicktarget" ).click(function() {alert( "handler .click() called." );}); $( "#ontarget" ).on('click',function() {alert( "handler .on() called." );}); 

my question whether there advantage of using bind() on on()? note documentation states "as of jquery 1.7, .on() method preferred method attaching event handlers document." instance, if element exists upon writing of dom, seems make sense. if so, there shortcut version of bind() binds on click?

$( "#bindtarget" ).bind( "click", function() {alert( "handler .bind() called" );}); 

from jquery source code :

bind: function( types, data, fn ) {     return this.on( types, null, data, fn ); }, 

as see, bind calls on. there's no reason use bind. never.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -