IE DOM

M

Maxim Demenko

Hello,
maybe it is a silly question, sorry in advance.
If i have a fragment like

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
</head>
<script type="text/javascript">
function t(){
vUl=document.getElementById("c");
alert(vUl.parentNode.getAttribute("id"));
}
</script>
<body>
<ul id="a">
<a href="#" onclick="t()">Root</a>
<li id="b">Level 1</li>
<ul id="c">
<a href="#">Level 1</a>
</ul>
</ul>
</body>
</html>

Then IE6 reports <li id="b"> as parent node for <ul id="c">, that is
apparently wrong for my understanding, FF in opposite works correctly.
Is it a well known bug ? Maybe , there are some workarounds for this issue ?

Best regards

Maxim
 
R

RobG

Maxim said:
Hello,
maybe it is a silly question, sorry in advance.
If i have a fragment like

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
</head>
<script type="text/javascript">
function t(){
vUl=document.getElementById("c");
alert(vUl.parentNode.getAttribute("id"));
}
</script>
<body>
<ul id="a">
<a href="#" onclick="t()">Root</a>
<li id="b">Level 1</li>
<ul id="c">

The above is invalid HTML. A UL can *only* have LI elements as
children, you should mark it up like:

<lu>
<li><a>...</a></li>
<li>
<ul>
<li>...</li>
<li>...</li>
<li>...</li>
</ul>
</li>
</il>

Note: closing tags on LI elements are optional, but with nested list the
markup can be very confusing without them (it's pretty confusing with
them too :) ).


[...]
Then IE6 reports <li id="b"> as parent node for <ul id="c">, that is
apparently wrong for my understanding, FF in opposite works correctly.
Is it a well known bug ? Maybe , there are some workarounds for this
issue ?

The issue is your markup. Browsers will convert it into a DOM depending
on guess work and error correction, the resultant DOM may well be
different in different browsers.
 
R

RobG

RobG wrote:
[...]
The above is invalid HTML. A UL can *only* have LI elements as
children, you should mark it up like:

<lu>
<li><a>...</a></li>
<li>
<ul>
<li>...</li>
<li>...</li>
<li>...</li>
</ul>
</li>
</il>

Owww! that is a hideous mess, sorry... try:

<ul>
<li><a>...</a></li>
<li>
<ul>
<li>...</li>
<li>...</li>
<li>...</li>
</ul>
</li>
</ul>

[...]
 
M

Maxim Demenko

RobG said:
RobG wrote:
[...]
The above is invalid HTML. A UL can *only* have LI elements as
children, you should mark it up like:

<lu>
<li><a>...</a></li>
<li>
<ul>
<li>...</li>
<li>...</li>
<li>...</li>
</ul>
</li>
</il>

Owww! that is a hideous mess, sorry... try:

<ul>
<li><a>...</a></li>
<li>
<ul>
<li>...</li>
<li>...</li>
<li>...</li>
</ul>
</li>
</ul>

[...]

Thanks a lot, you saved me hours of headaches!!!

Best regards

Maxim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,142
Latest member
DewittMill
Top