Problem description:

Can't access child tag by lastChild or childNode

Code:

-------------------------------------------------------------------------------------------------

<html>
<body>


<p id="intro">
Hello World!
<h4 id="second">This is the second child of p with id intro.</h4>
</p>


<script type="text/javascript">


x=document.getElementById("intro");
try{
document.write(x.lastChild.nodeValue);
}catch(err){
alert(err.description);
}


</script>
<!--
why can't I get access to h4's text node value ??
-->


</body>
</html>

-------------------------------------------------------------------------------------------------

Solution:

Actually it is not a solution......

Seems like that h4 is body's child node instead of p's

This bug might result from the properties of the tag since that both p and h4 belong to text tag

If we replace p with div it will display as we have expected.

guardian801202 發表在 痞客邦 PIXNET 留言(0) 人氣()