Event handler triggered twice instead of once
Posted
by kwokwai
on Stack Overflow
See other posts from Stack Overflow
or by kwokwai
Published on 2010-04-28T06:44:31Z
Indexed on
2010/04/28
6:53 UTC
Read the original article
Hit count: 270
Hi all,
I am sorry that I have asked two questions in a few minutes.
In a html file, I got three child DIV tags in a parent DIV tag:
<div id="container">
<div id="frag-123">123</div>
<div id="frag-124">124</div>
<div id="frag-125">125</div>
</div>
Now when I click either the three child DIV tags, I will see two alert boxes pop up instead of one: The first alert box will show something like this: frag-123, and the second alert box will show something like this: container
I dont know why. I just want to get the ID value of a child DIV, not the one from the parent DIV.
<script>
$(function() {
$("div").click(function() {
var imgID = this.id;
alert(imgID);
});
});
</script>
Please help.
© Stack Overflow or respective owner