473,231 Members | 1,675 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,231 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 2060
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 "デスクトップ". 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: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.