1.

Solve : HTML DOM help?

Answer»
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?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
}


Discussion

No Comment Found