473,474 Members | 1,661 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Questions On Enumerating DOM childNodes

Please help.....

I am starting to learn using javascript on DOM. One of the first things
I tested was listing all the child nodes from an element. Like ->

*html code:
<div id="pagetitle">
<span>My Text</span>
</div>

In my javascript I tried to list all the child nodes from <div>, Firefox
and Opera gave me 3 -- 1)text node with a null value, 2)span, 3)text
node with a null value.

It look to me that the browsers treated the line break as a text node
with no value!!

If I modified the html code to :
<div id="pagetitle"><span>My Text</span></div>

Then the browsers gave me the right answer: 1

They still gave me a wrong answer of 3 if I put a space around the
<spanelement like this:
<div id="pagetitle"<span>My Text</span</div>

What did I do wrong? I would still want the elements to be on their own
lines.

Thank you.
Jan 7 '07 #1
2 2124
VK

Louis wrote:
Please help.....

I am starting to learn using javascript on DOM. One of the first things
I tested was listing all the child nodes from an element. Like ->

*html code:
<div id="pagetitle">
<span>My Text</span>
</div>

In my javascript I tried to list all the child nodes from <div>, Firefox
and Opera gave me 3 -- 1)text node with a null value, 2)span, 3)text
node with a null value.

It look to me that the browsers treated the line break as a text node
with no value!!

If I modified the html code to :
<div id="pagetitle"><span>My Text</span></div>

Then the browsers gave me the right answer: 1

They still gave me a wrong answer of 3 if I put a space around the
<spanelement like this:
<div id="pagetitle"<span>My Text</span</div>

What did I do wrong? I would still want the elements to be on their own
lines.
see
<http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/16964dfe3f4809a0>

Jan 7 '07 #2

Louis wrote:
Please help.....

I am starting to learn using javascript on DOM. One of the first things
I tested was listing all the child nodes from an element. Like ->

*html code:
<div id="pagetitle">
<span>My Text</span>
</div>

In my javascript I tried to list all the child nodes from <div>, Firefox
and Opera gave me 3 -- 1)text node with a null value, 2)span, 3)text
node with a null value.
Safari will too.
>
It look to me that the browsers treated the line break as a text node
with no value!!

If I modified the html code to :
<div id="pagetitle"><span>My Text</span></div>

Then the browsers gave me the right answer: 1
You mean the answer you expected. :-)
>
They still gave me a wrong answer of 3 if I put a space around the
<spanelement like this:
<div id="pagetitle"<span>My Text</span</div>

What did I do wrong? I would still want the elements to be on their own
lines.
Some browser developers decided to preserve whitespace within documents
using #text nodes as they believe that is in accordance with the
specification. It applies to browsers other than Gecko-based ones
(such as Firefox and Mozilla) and Opera. IE behaves differently and
removes such whitespace from the DOM tree and from the innerHTML
property also.

Regardless of which approach you think is right or wrong, the fact is
that you need to deal with it and know that when traversing down the
DOM tree you may encounter #text nodes in some browsers but not others.

--
Rob

Jan 7 '07 #3

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

Similar topics

1
by: Carlos Kirkconnell | last post by:
I'm programming a multi - threaded application using C#. I have two questions regarding to the use of threads 1- I have a Hashtable that will have multiple writters and multiple readers. I used...
3
by: Christopher Benson-Manica | last post by:
(Sorry for the duplicate post - I was going to change the subject before posting and forgot...) I'm trying to create script that can dynamically execute script from a given source and then call...
1
by: ason | last post by:
Hi, I just tried to replace a single XmlNode with several ChildNodes. When doing this with the following code i found out that if you get the ChildNodes with 'ChildNodes' - property the nodes...
50
by: Jatinder | last post by:
I 'm a professional looking for the job.In interview these questions were asked with some others which I answered.But some of them left unanswered.Plz help. Here are some questions on C/C++, OS...
2
by: Tony | last post by:
I have this problem - I have a hashtable, containing a list of filenames. Every 60 seconds, I have a thread that enumerates thru this hashtable, and based on some simple logic, some of the items...
2
by: chuck | last post by:
Hi, I am modifying some code from here http://www.quirksmode.org/dom/domform.html I have a div 'readroot' that I clone. I change the change the id and name of the childnodes of 'readroot' to...
3
by: Q1tum | last post by:
Hi all, I have a problem with getting the amount of childs in a XML structure, the strucure is somewhat like the following: <?xml version="1.0" encoding="iso-8859-1"?> <cms> <num>21</num>...
1
by: yawnmoth | last post by:
Given an element ID, is there a way to figure out what index one would need to use in the parentNode's childNodes array to get at that element? For example... <body> <div id="parent"> <div...
5
by: Moses | last post by:
HI The Value for childNodes.length differs with mozilla and IE Is it problem with my coding..... I could not under stood............. The following is the details
2
by: willyWEB66 | last post by:
Hi everyone, I have this code in javascript where the XML file is loaded and displayed to an html using XSLT. It works fine in IE but not in Firefox. My problem is in the looping to the...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.