Hube02
asked on
Get Children
How would I get the first level children and not get the grandchildren as well
for instance
<div id="topLevel">
<div>
<div>
</div>
</div>
<div>
</div>
<div>
so, if I am starting from the div with the ID of "topLevel" how do I get the child div's one level down and not the grandchild div. I've tried getElementByTagName and this returns all three div's when I only want to get 2 of them.
for instance
<div id="topLevel">
<div>
<div>
</div>
</div>
<div>
</div>
<div>
so, if I am starting from the div with the ID of "topLevel" how do I get the child div's one level down and not the grandchild div. I've tried getElementByTagName and this returns all three div's when I only want to get 2 of them.
ASKER
You've lost me.
What does VBScript have to do with getting elements in JavaScript.
The purpose of this is so that I can set style properties dynamically.
What does VBScript have to do with getting elements in JavaScript.
The purpose of this is so that I can set style properties dynamically.
Use the childNodes collection, but remember to check if each node is an element node by checking if the node's nodeType property is set to 1 or not.
ASKER
Not one to sit around and wait, I tried childNodes last night. The problem with this is that if there is some other type of element in there that is returned as well.
For instance if you have:
<div>
<div></div>
<span><span>
</div>
Both the div and the span are returned as element type 1. It seems no matter which route I go, I'm getting more information than I want.
Is there any way to tell what type of element each of the childNodes really is? Is it a div, span, ul. Seems to me there should be some way to get only the first level children of a specific element type.
For instance if you have:
<div>
<div></div>
<span><span>
</div>
Both the div and the span are returned as element type 1. It seems no matter which route I go, I'm getting more information than I want.
Is there any way to tell what type of element each of the childNodes really is? Is it a div, span, ul. Seems to me there should be some way to get only the first level children of a specific element type.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window