javascript - Preventing jquery event triggering from sub elements -



javascript - Preventing jquery event triggering from sub elements -

i have next code:

<html> <head> <script src="http://code.jquery.com/jquery-1.6.2.min.js" type="text/javascript"> </script> </head> <body> <div id="a"> <div id="b"> <script type="text/javascript"> $('#b').bind('fuffle',function() {alert('b fuffled');}) </script> <div id="c"></div> </div> </div> </body> </html>

when run

$("#b").trigger('fuffle')

i alert box expect. however, when run

$("#c").trigger('fuffle')

i alert box. guessing because c nested in b, however, there technique behavior avoided.

in code, sub elements can trigger fuffle, bound different method. behavior literally causing js stackoverflow error.

try passing event anonymous handler function

...'fuffle', function(e) {alert...

then call

e.stoppropagation()

which prevent event bubbling. more blunt approach homecoming false.

http://api.jquery.com/event.stoppropagation/

javascript jquery events javascript-events

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -