...

View Full Version : getting nodeValue in IE



leftpeg
03-19-2004, 07:46 AM
The following code works OK (i.e the alert displays "Testing") in Mozilla 1.6 but generates a javascript error in IE6. Any pointers as to why would be appreciated.

<html>
<head>
<script language="javascript">
function testingDOM(){
var title;

title = document.getElementsByTagName("title");
alert(title.item(0).firstChild.nodeValue);
}
</script>
<title id="title">Testing</title>
</head>
<body>
<input type="button" value="click me" onClick="testingDOM()"/>
</body>
</html>


Also, if i change my function to the following
title = document.getElementById("title");
alert(title.firstChild.nodeValue);

it doesn't work at all.

Why is this?

Cheers

swmr
03-19-2004, 09:05 AM
That could be related to this bug (http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/q296/1/13.asp&NoWebContent=1).
Using the text property of title, or title property of document might be alternatives...

leftpeg
03-19-2004, 09:28 AM
That's very interesting, thanks.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum