Howto: div with onclick inside another div with onclick javascript
Solution 1:
Basically there are two event models in javascript. Event capturing and Event bubbling. In event bubbling, if you click on inside div, the inside div click event fired first and then the outer div click fired. while in event capturing, first the outer div event fired and than the inner div event fired. To stop event propagation, use this code in your click method.
if (!e) var e = window.event;
e.cancelBubble = true;
if (e.stopPropagation) e.stopPropagation();
Solution 2:
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:
function myClickHandler(e)
{
// Here you'll do whatever you want to happen when they click
// now this part stops the click from propagating
if (!e) var e = window.event;
e.cancelBubble = true;
if (e.stopPropagation) e.stopPropagation();
}
Solution 3:
Just add this code :
window.event.stopPropagation();
Solution 4:
return false;
from the inner div's onclick function:
<div onclick="alert('inner'); return false;" ...
What you're dealing with is called event propagation.
Solution 5:
This is a case of event bubbling.
You can use
e.cancelBubble = true; //IE
and
e.stopPropagation(); //FF