Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting an array of nested elements 1

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
how do I grab an object such as a div including all its child objects such as the <ul>, <li> , <a> etc...

If I create an object using getElementById does this also get the child nodes? and if so how do I refer to them, and if not how do I create an object which holds an element and it's child nodes so I can then apply style attributes to the child elements. ?

thanks 1DMF.



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
I'm not expert in this but wouldn't this give you what you need?


Code:
var children = document.getElementById('myElement').childnodes

I think that will give you an array of the children of myElement. Then you can loop through it and do what you want to them.

<honk>*:O)</honk>
Designease Ltd. - polyprop folders, ring binders and creative presentation ideas
Earl & Thompson Marketing - Marketing Agency Services in Gloucestershire
 
thanks, i've actually found this peice of code which helped me to acheive what i needed
Code:
navHover = function() {
	[b]var lis = document.getElementById("navmenu").getElementsByTagName("LI");[/b]
	for (var i=0; i<lis.length; i++) {
		lis[i].onmouseover=function() {
			this.className+=" iehover";
		}
		lis[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" iehover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", navHover);

It shows how you can grab the ElementById and concatinate the ByTagName into an array.

the problem that's been driving me mad is the CSS bit , but I think i've nearly cracked it :)



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top