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

java - How to pass parameters between Request-Scoped Controllers? -

string - what is the difference between "some" == "some\0" and strcmp("some","some\0") in c++? -

actionscript 3 - Flex: moving a point with rotation doesnt change the point XY? -