Entry
How can I attach mouseover/mouseout handlers to a DIV or SPAN in NN4?
How can I attach mouseover/mouseout handlers to a DIV or SPAN in NN4?
Apr 3rd, 2000 11:45
Martin Honnen,
With IE4+ and NN6 you can define your event handlers as HTML attributes
e.g.
<DIV ONMOUSEOVER="alert(event.type);"
ONMOUSEOUT="alert(event.type);"
>
With NN4 that is only supported for the LAYER tag. You can however use
JavaScript to attach event handlers to an absolutely positioned DIV or
SPAN as the following example shows:
<HTML>
<HEAD>
<STYLE>
#aDiv { position: absolute; }
.js {
color: white;
background-color: orange;
}
</STYLE>
<SCRIPT>
function initEventHandlers () {
if (document.layers) {
document.aDiv.onmouseover =
document.aDiv.onmouseout = function (evt) {
alert(evt.type);
};
}
}
</SCRIPT>
</HEAD>
<BODY ONLOAD="initEventHandlers()">
<DIV ID="aDiv" CLASS="js"
ONMOUSEOVER="alert(event.type);"
ONMOUSEOUT="alert(event.type);"
>
JavaSript.FAQTs.com
</DIV>
</BODY>
</HTML>
Also see
http://www.faqts.com/knowledge-base/view.phtml/aid/1000/fid/145/lang/en
on how to use dynamic layer creation to attach event handlers for
inline content.