jQuery events priority when element within an element is clicked -
<script> $(document).ready(function() { $("a").click(function(){ alert("anchor clicked !") }); $("p").click(function(){ alert("p clicked !") }); }); </script> </head> <body> <a href = "#"><p>click me ! </p> </a> </body> </html> when click on link first alert("p clicked !") , alert("anchor clicked !") appears.
i want know behaviour observed ?
p.s. : couldn't come appropriate title edit welcome
this due event bubbling
when use event bubbling
/ \ ---------------| |----------------- | element1 | | tag | | -----------| |----------- | | |element2 | | p tag | | ------------------------- | | event bubbling | ----------------------------------- read what event bubbling , capturing?
to prevent event bubbling
Comments
Post a Comment