Claudio,
I don't know why it doesn't work. What I do know is that event.raget
will work in Gecko-based browsers as well.
But in your HTML code you use the LAYER tag. That tag ONLY works in
Netscape 4. You should use DIV tags instead.
/Robert
-----Ursprungligt meddelande-----
Fr=E5n: Claudio Pallone [mailto:pallone@l...]
Skickat: den 7 november 2002 10:34
Till: JavaScript HowTo
=C4mne: [javascript_howto] Return Key/Enter Key Event Handler part III
Hi Robert,
I have read the article on:
http://www.javascriptkit.com/dhtmltutors/nsevents.shtml
http://webreference.com/js/column74/
and found it very helpfull. Many thanks for the URL.
Howerver, there is a problem with one of the examples in the tutorial:
This should work for all browsers I believe:
var layer=3Devent.srcElement || event.currentTarget || event.target;
event.srcElement is for IE4+,
event.currentTarget is for Gecko-based browsers
event.target is for NS4
But it does not work for NS6+ on the mouseout event!! It works with the
onmouover but not onmouseout. This is strange isn't it??
Please, do you know what I have to add to this line
var layer=3Devent.srcElement || event.currentTarget || event.target;
so that it works for NS6+ as well??
Cheers,
Claudio
<html>
<head>
<script language=3D"Javascript">
function bgChange(bgc)
{
if (!window.event)
{
event=3Darguments.callee.caller.arguments[0];
}
var layer=3Devent.srcElement || event.currentTarget ||
event.target;
if (layer.style)
{
layer.style.backgroundColor=3Dbgc;
}
else
{
layer.bgColor=3Dbgc;
}
=09
}
</script>
</head>
<body>
<ilayer>
<layer onmouseover=3D"bgChange('green')" onmouseout=3D"bgChange
('white')">
<span onmouseover=3D"bgChange('green')"
onmouseout=3D"bgChange ('white')">BG Color Change</span>
</layer>
</ilayer>
</body>
</html>