just a quick question. I'm having a problem with divs with onclick javascript within each other. When I click on the inner div it should only fire it's onclick javascript, but the outer div's javascript is also being fired. How can the user click on the inner div without firing the outer div's javascript?
<html>
<body>
<div onclick="alert('outer');" style="width:300px;height:300px;background-color:green;padding:5px;">outer div
<div onclick="alert('inner');" style="width:200px;height:200px;background-color:white;" />inner div</div>
</div>
</div>
</body>
</html>
return false;
from the inner div's onclick function:What you're dealing with is called event propagation.
One more way for webkit based browsers:
Here is some more reference to help you in understanding javascript event bubbling.
Check out the info on event propagation here
In particular you'll want some code like this in your event handlers to stop events from propagating:
This was very helpful, but it didn't work for me.
What i did is described here.
So I put a condition to the outer
onclick
event:You can use