I have a div containing another div. If the user clicks on the inner div, I want the event handler attached to this element to execute. Right now, the event handler of the inner element is executed first, and then the outer element. Is there any way to change this?
<html> <head> <meta charset="utf-8"> <title>Demo</title> </head> <body> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script> <script> $(document).ready(function(){ $("#containerElement").click(function(event){ alert("This comes from container"); }); $("#innerElement").click(function(event){ alert("This comes from inner element"); }); }); </script> <div id="containerElement" > This is the container <div id="innerElement" > This is the inner element </div> </div> </body> </html>
source share