javascript - Jquery event handling order: click on ele: itself or parent first? -


i have following click event handlers:

 $('html').click(function() { something});  $('#my_div').click(function() { something}); 

my_div descendant of html.

if click on my_div, can control called first? can depend on my_div handler being handled first?

the child event handler called before parent event handler (event bubbling). when click #my_div, click event handler called. here, have option stop event bubble html click handler using

event.stoppropagation() 

i.e.

$('#my_div').click(function(event) {     event.stoppropagation(); }); 

note: when using jquery, event.stoppropagation() may not work in browsers. have take event argument in click handler

ie. $('#my_div').click(function(event){ ... });


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -