Bind an element and its children in jQuery

I want to associate an event with an element and its children. What is the best way to do this?

$(element).bind('click', function(event) { doSomething(); }); 
+4
source share
2 answers
 $(element).bind('click', function(event) { doSomething(); }).children().bind("click",function(event){ // code to handle children click here event.stopPropagation(); // if you don't want event to bubble up }); 
+5
source

The code you have will do just that.

Look in the target field to see which actual child node has seen the event.

0
source

All Articles