javascript not working properly in Mozilla v1.0 but same code is working fine in IE v6.0

Axel Richter

Hi,

the property [Node].firstCild contains the first cild node of the given node. This node may be a text node or a element node. For example:

<div id="mydiv">
<p>test</p>
</div>
<script type="text/javascript">
<!--
var node = document.getElementById("mydiv");
alert(node.firstChild.nodeType);
//-->
</script>
MSIE alerts "1", that is the element node P. Mozilla alerts "3", that ist the text node whitespace between begin of DIV and begin of P. For nodes look at http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1950641247.

You have to test which node type you've gotten with .firstChild or you have to get the desired element directly with getElementById().

Greetings

Axel
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact