I have a div that contains another div.
If the user clicks the inner div I only want the eventhandler attached to this element get executed. Right now first the eventhandler of the inner element and then that of the outer element gets executed. Is there a 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>
You could stop the propagation: