473,398 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

firstChild not working in Netscape 7.1??

Friends,

the Javascript function firstChild() works as expected in IE but
returns "undefined" in Netscape 7.1

Here is the sample html code that I used. I am asking the javascript
to print out the id of the child of para1. IE correctly prints the
string "italicsid", but Netscape gives me an "undefined". Why so? Any
help is greatly appreciated.

Thanks,
Prasanna
<html>
<head>
<script LANGUAGE="Javascript">

function GetFirstChild(which)
{
curr = document.getElementById(which);
{
alert(curr.firstChild.id) ;
}
}

</script>

</head>
<body>
<p class=insert id=para1 onclick="GetFirstChild('para1')">
<i id="italicsid" name="italicsname">
Child of para1
</i>
</p>
</body>
</html>
Jul 20 '05 #1
1 2520


Prasanna wrote:
the Javascript function firstChild() works as expected in IE but
returns "undefined" in Netscape 7.1
firstChild is not a function, neither with IE nor with Netscape.
Here is the sample html code that I used. I am asking the javascript
to print out the id of the child of para1. IE correctly prints the
string "italicsid", but Netscape gives me an "undefined". Why so? Any
help is greatly appreciated.
In Netscape's DOM white space text nodes are modelled while IE throws
them out, therefore with Netscape the first child node is a text node
and not an element node, and text nodes don't have an id property which
is why you get undefined for the id.
You need to check whether
node.nodeType == 1
to find out whether something is an element node.
<html>
<head>
<script LANGUAGE="Javascript">

function GetFirstChild(which)
{
curr = document.getElementById(which);
{
alert(curr.firstChild.id) ;
}
}

</script>

</head>
<body>
<p class=insert id=para1 onclick="GetFirstChild('para1')">
<i id="italicsid" name="italicsname">
Child of para1
</i>
</p>
</body>
</html>


--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: David | last post by:
After getting some help working through my bugs, I have what seems to be a robust, working word counter script. I post it here to benefit others that might want this in the future and so that if I...
2
by: schieco | last post by:
The following code always prints the debug lines inside the conditional if statement before and after the alert statement when the session has timed out, but the alert and redirect only appear/work...
0
by: Tim | last post by:
Hello, I notice that an XmlElement and an XmlDocument can both have identical OuterXml, yet different values for FirstChild. For example, in the method below, if you pass in an XmlDocument then...
5
by: moondaddy | last post by:
I have a <a> element in a datagrid which wraps some asp.net labels. this element also has an onclick event which does not fire in netscape 6 (and perhaps other browsers for all I know...). Below...
8
by: cp | last post by:
II have an HTML <td> element defined as : <td onclick="someFunction(this)"> <div id="myDivId">text</div> </td> I want, in someFunction() access to the id of the child div node. I see a...
7
by: Joe | last post by:
I've been playing around with atlas for hte past couple days and its very impressive. However the standard browser here is Netscape, specifically: Netscape 7.02 Mozilla/5.0 (Windows; U; Windows NT...
9
by: retrofill | last post by:
Hey i've got a problem with printing out an XML document: XML doc: http://www.deniseburrows.pwp.blueyonder.co.uk/javascript/data.xml If i remove the comments from the lines that add the...
3
by: szimek | last post by:
Hi! Like many others before recently I've found out that firstChild works little bit differently in IE and other browsers. I've got huge app that is currently IE only and used firstChild all...
1
by: neilfarah | last post by:
I have tried with one for loop or two for loops. I've even separated each firstChild.nodeValu e by a semicolon and I still get the same result. It will print with one of the nodeValues, but not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.