Event fired on the wrong object

  • Thread starter Thread starter Claude Schneegans
  • Start date Start date
C

Claude Schneegans

Hi,

Please see here: http://www.contentbox.com/claude/test/testEvent.htm

The script scans all LI objects and attach a onmouseon event to each of
them.

In the function called by the event, the tagname of the object is check,
and if it is not LI,
an alert is given.

Just move the mouse over the objects, and from time to time, you will
get an alert
and see that the event has been fired on an UL object. How come, since
none of them
has an event attached.

Is it some known bug?

It also seems to affect Mozilla.

Here is the code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>Untitled</title>
<STYLE>
ul {
background-color: #B9D2FF;
margin:0px;
padding: 0;
position:absolute;
border: solid 1px #AAAAAA;
}
ul li {
width: 125px;
margin: 0;
padding: 0;
background-color: #628BFF;
color: #DFE6F5;
border: 1px outset;
list-style: none;
}
UL LI UL {
left:110px;
top:5px;
}

</STYLE>
</head>

<body>
<UL id="0">
<li id="1">item 1
<UL id="1.0">
<li id="1.1">item 1.1</li>
<li id="1.3">item 1.3</li>
<li id="1.4">item 1.4</li>
</ul></li>
<li id="2">item 2</li>
<li id="3">item 3</li>
<li id="4">item 4</li>
</ul>
<SCRIPT>
function init(m)
{
var el = m.childNodes;
for (var l = 0; l<el.length; l++)
{
if(el[l].tagName)
{
var tag = el[l].tagName.toLowerCase();
if (tag == "ul")
{
//do not attach event if UL container, but process its LIs
init (el[l]);
}
else if (tag == "li")
{
//attach event to list element ONLY
if(document.all)el[l].attachEvent('onmouseover', show);
else el[l].addEventListener("mouseover", show, false);
init (el[l]);
}
}
}
}
function show(e)
{
var li;
if (document.all)li=event.srcElement;
else li=e.target;
if (li.tagName != "LI")alert("over" + li.id + " : tag is " +
li.tagName);
}
init(document.body);
</SCRIPT>

</body>
</html>
 
Back
Top