473,394 Members | 1,694 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,394 software developers and data experts.

getting the children

I am having a <div> with <a>s and <div>s inside it.

I am trying to read in all the elements in the right order.

With mydiv.getElementsByTagName("a") I can get the elements of a specific
tag like "a", but I want all types.

I tried getChildNodes but that doesn't seem to be widely supported.
childNodes[] seemed to do something but I couldn't get it working when I
wanted to browse through the elements.

What is the best way to do this?

A related question. If I have an element, how can I see which type (a, div,
input,etc) it is?

Thanks,

Wim
Jul 23 '05 #1
3 2068
On Sat, 18 Sep 2004 18:39:13 +0200, Wim Roffal
<wi*************@nospamm-planet.nl> wrote:

[snip]
I tried getChildNodes but that doesn't seem to be widely supported.
Probably because it doesn't exist. It's not part of Microsoft's DOM, or
the standardised W3C DOM (unless it's in Level 3).
childNodes[] seemed to do something but I couldn't get it working when I
wanted to browse through the elements.

What is the best way to do this?
Mind showing what you were trying to do? The childNodes collection is your
best bet.
A related question. If I have an element, how can I see which type (a,
div, input,etc) it is?


Use the nodeName property. This will return a case-sensitive string with
the element name. In HTML, the string will always be in uppercase.

Hope that helps,
Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2
Michael Winter wrote:
On Sat, 18 Sep 2004 18:39:13 +0200, Wim Roffal
<wi*************@nospamm-planet.nl> wrote:

[snip]
I tried getChildNodes but that doesn't seem to be widely supported.

Probably because it doesn't exist. It's not part of Microsoft's DOM, or
the standardised W3C DOM (unless it's in Level 3).
childNodes[] seemed to do something but I couldn't get it working when
I wanted to browse through the elements.

What is the best way to do this?

Mind showing what you were trying to do? The childNodes collection is
your best bet.


To help you out, childNodes returns a collection,
you can do something like:

var a = document.getElementById('aDiv').childNodes;
for (var i=0; i<a.length; ++i) {
// do something to each child
}

Other useful methods are firstChild and nextSibling - which is
really useful if you start at some unknown point in a DOM and
just want the next sibling. Say you want to find the next one
after "a" above without having to find the parentNode, work out
the index of "a", then get the next one. It's all
done by "var b = a.nextSibling".
A related question. If I have an element, how can I see which type
(a, div, input,etc) it is?

Use the nodeName property. This will return a case-sensitive string
with the element name. In HTML, the string will always be in uppercase.


There is also nodeType, but different browsers seem to put
different node types in some places so it may not be that
useful for you.
Cheers, Fred.
Jul 23 '05 #3
On Sun, 19 Sep 2004 16:02:50 +1000, Fred Oz <oz****@iinet.net.auau> wrote:

[snip]
On Sat, 18 Sep 2004 18:39:13 +0200, Wim Roffal
<wi*************@nospamm-planet.nl> wrote:
[snip]
A related question. If I have an element, how can I see which type
(a, div, input,etc) it is?

[snip]
There is also nodeType, but different browsers seem to put
different node types in some places so it may not be that
useful for you.


The nodeType property doesn't return the information the OP wanted,
though. It returns quite literally the type: element, comment, DOCTYPE,
text, etc. However, that information does prove very useful when iterating
through the tree when looking for generic types. If you're looking for a
specific element, such as an INPUT, there isn't much need for it.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #4

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

Similar topics

303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
2
by: Eyal | last post by:
Hey, I would appriciate if anyone can help on this one: I have a java object/inteface having a method with a boolean parameter. As I'm trying to call this method from a javascript it fails on...
1
by: Todd Cary | last post by:
In my previous post, I stated that some JavaScript I inherited does not work in Firefox but does work in IE 6 . I have now isolated a line where it fails in Firefox; the line with the property of...
6
by: Luke Dalessandro | last post by:
I'm not sure if this is the correct forum for platform specific (Mozilla/Firefox) javascript problems, so just shout and point me to the correct newsgroup if I'm being bad. Here's the deal... ...
12
by: Sunny | last post by:
Hi All, I have a serious issue regarding classes scope and visibility. In my application, i have a class name "TextFile", and also a few other classes like "TotalWords", "TotalLines" and etc..,...
27
by: Richard Blewett [DevelopMentor] | last post by:
I've just seen on Eric Gunnerson's blog that C# is getting Edit and Continue in Whidbey. That will please alot of people - although me, I have mixed feelings about it ;-) ...
3
by: Andrej Pavlovic | last post by:
Hi, Please look at the following HTML snippet: <body> some text <p>more text</p> even more text </body>
4
by: Andrew May | last post by:
This is only my first AJAX based application so this may be a trivial question but I cannot find any way of getting at the data I want. So, I have an XML file of the form: <data>...
5
by: Sin Jeong-hun | last post by:
Hello. Speical folders, like Desktop, usually have different display names. For example, in Japanese Windows, it's displayed as "$B%G%9%/%H%C%W(B". I want to get the this displayed name of a...
1
by: duane.lortie | last post by:
I'm writing a routine that fetches XML and attempts to parse some values from it. A condensed entry node of the XML looks like this .. <entry> <title>Some title</title> <author>...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...

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.