D
deepwater
Imagine, if you will, a span (with text) inside of a div which has a
black border. I assign the onMouseOut event of the div to color it
white, i.e., make it disappear. But when I mouse out of the span
(while still in the div), the border also turns white. I don't want
this. I understand that the onMouseOut event is bubbling up to the
parent element. And I have read and tried (for several hours now
how to prevent this behavior by attaching an onMouseEvent to the span
which captures the event and stops it from bubbling/propagating up to
the div. But I can't get this to work on Firefox, Safari or IE and
don't know why. The code in cancelEvent is identical to numerous
samples I've seen on the web. Ideas, anyone?
<html>
<head>
<script language=javascript>
function cancelEvent(e){
var e = e || window.event;
if (e.stopPropagation) {
e.stopPropagation();
} else {
e.cancelBubble = true;
e.returnValue = false;
}
}
function hideBorder(divObj){
divObj.style.borderColor="#ffffff";;
}
function showBorder(divObj){
divObj.style.borderColor="#000000";
}
</script>
</head>
<body>
<div id="mydiv" style="border:1px solid #000000; width:800px;"
onMouseOut="hideBorder(this);" onClick="showBorder(this);">
<br><br><br>
<span onMouseOut="cancelEvent(event);">mousing over should NOT
cause the box to disappear</span>
<br><br><br>
</div>
</body>
</html>
black border. I assign the onMouseOut event of the div to color it
white, i.e., make it disappear. But when I mouse out of the span
(while still in the div), the border also turns white. I don't want
this. I understand that the onMouseOut event is bubbling up to the
parent element. And I have read and tried (for several hours now
how to prevent this behavior by attaching an onMouseEvent to the span
which captures the event and stops it from bubbling/propagating up to
the div. But I can't get this to work on Firefox, Safari or IE and
don't know why. The code in cancelEvent is identical to numerous
samples I've seen on the web. Ideas, anyone?
<html>
<head>
<script language=javascript>
function cancelEvent(e){
var e = e || window.event;
if (e.stopPropagation) {
e.stopPropagation();
} else {
e.cancelBubble = true;
e.returnValue = false;
}
}
function hideBorder(divObj){
divObj.style.borderColor="#ffffff";;
}
function showBorder(divObj){
divObj.style.borderColor="#000000";
}
</script>
</head>
<body>
<div id="mydiv" style="border:1px solid #000000; width:800px;"
onMouseOut="hideBorder(this);" onClick="showBorder(this);">
<br><br><br>
<span onMouseOut="cancelEvent(event);">mousing over should NOT
cause the box to disappear</span>
<br><br><br>
</div>
</body>
</html>