Jquery select div inside div

I am trying to get this to warn only that the div has clicked, and also notifies me of the div element pressed, and then the div container. when I click on the third div, I would like it to only warn the "third". thanks for the help.

<div id="first"> <div id="second"> <div id="third"> third div </div> second div </div> first div </div> $("div").click(function() { alert(this.id); }); 
+4
source share
4 answers

Demo

 $("div").click(function(e) { alert(this.id); e.stopPropagation(); }) 

who will do it.

+4
source

event.stopPropagation ();

 $("div").click(function(event) { alert(this.id); event.stopPropagation(); }) 
+2
source
 $("div").click(function(event) { alert(this.id); event.stopPropagation(); }) 
+2
source
 $("div").click(function() { alert(this.id); return false; }) 
+2
source

All Articles