Forum Moderators: open

Message Too Old, No Replies

viewing all the properties and objects in the DOM

with a recursive loop?

         

httpwebwitch

4:08 pm on Nov 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is there a way to view a tree list of DOM elements, so I can easily get the ID names and properties and stuff?

for instance, can I get a list of all the objects that are in "document", or "myiframe" or "document.style", so I can choose them for use in my scripts?

Bernard Marx

4:58 pm on Nov 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



document:

var all = document.getElementsByTagName('*')
This gives a collection of all document elements. When you loop through this numerically, the elements will come out in source order.

myIframe
Get the iframe's document, then as above.
The iframe itself will have properties too.

document.style

Hmmm. I don't think the docuemnt has a style object.
If you want the properties of element.style, then you can use a for..in loop to enumerate.


for(var p in element.style)
alert(p +': '+ element.style[p])

In some (all?) implementations, this will 'reveal' properties of the style object, and CSS properties that you haven't explicitly defined.