Reputation: 41
I am trying to get this to alert only the div clicked on, vs alerting the div clicked and then the container div's. when I click on the third div I would like it to only alert "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);
});
Upvotes: 4
Views: 543
Reputation: 408
$("div").click(function(event) {
alert(this.id);
event.stopPropagation();
})
Upvotes: 2
Reputation: 7525
$("div").click(function(event) {
alert(this.id);
event.stopPropagation();
})
Upvotes: 2
Reputation: 78570
$("div").click(function(e) {
alert(this.id);
e.stopPropagation();
})
that will do it.
Upvotes: 4