javascript - is jquery on() always better than bind() -
this question has answer here:
- what's difference between `on` , `live` or `bind`? 7 answers
- jquery’s .bind() vs. .on() 6 answers
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
Post a Comment