Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: HTML DOM help  (Read 3136 times)

0 Members and 1 Guest are viewing this topic.

shammer

  • Guest
HTML DOM help
« on: June 19, 2007, 11:25:40 AM »

Hi I am new to HTML dom.

Basically i just want to know how to access all the elements in the html document using the dom framework. So far i have document.childNodes which just gives me an array with the HTML root element in it. I need to look at all the elements in the head and the body to extract thier ids (if they have one only).

Basically the end result of my javascript function is to extract all the html id values from a simple html document.

any suggestions?

Saint_Jude

  • Guest
Re: HTML DOM help
« Reply #1 on: June 20, 2007, 10:34:21 AM »
Code: [Select]
// Need to wait until doc has loaded.

onload = function(){
var ids  = [];
var elms = document.getElementsByTagName("*");

// Loop stops when elms[k] returns null
for(var k=-1, elm; elm=elms[++k]; )
if(elm.id) // if id exists, and is not zero length
ids.push(elm.id);

// Now ids array contains all id strings
}