triggers - jquery: What happens after binding an event more than once? -


thanks jquery, .on method binds trigger element. have html like:

<div class='xyz'>click me</div> 

and script like:

$('.xyz').on('click', function(){   alert('why?'); }); $('.xyz').on('click', function(){   alert('why?'); }); 

clicking on click me div triggers alert 2 times. it's ok, but:

  1. what happens after binding second click trigger div?
  2. is browser behavior or done jquery variables?

here fiddle: http://jsfiddle.net/hpmhpm/fcrec/

what happens after binding second click trigger div?

jquery register's new click event handler on .xyz, no matter, how many event handler's attached element

is browser behavior or done jquery variables?

it's done jquery


you can have many event handler's want on same element, consider scenario -

this valid :

$('.xyz').on('click', function(){   // work }); $('.xyz').on('click', function(){   // other work }); 

Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -