Javascript/DOM
-
Hello, I am trying to write a simple javascript function. I want to read in the values of heading nodes in an HTML document and then make a list of them. I want to then use this to make a template which contains a menu which can update the navigation bar depending on the html content. the code I used is
var headings1 = getElementsbyType('h1');
then I tried to access the element to produce a list using a for loop
var temp ="<p>"
for (i=0; ito make a list something like
NO. of H1s
firstchild
secondchild
etc..
No. of H2s
etc etc..I''m quite new to DHTML, can anyone spot what I'm doing wrong?
thanks(or suggest a good tutorial?)Andy
-
Hello, I am trying to write a simple javascript function. I want to read in the values of heading nodes in an HTML document and then make a list of them. I want to then use this to make a template which contains a menu which can update the navigation bar depending on the html content. the code I used is
var headings1 = getElementsbyType('h1');
then I tried to access the element to produce a list using a for loop
var temp ="<p>"
for (i=0; ito make a list something like
NO. of H1s
firstchild
secondchild
etc..
No. of H2s
etc etc..I''m quite new to DHTML, can anyone spot what I'm doing wrong?
thanks(or suggest a good tutorial?)Andy
Check out Microsoft's Documentation[^] on getElementsByTagName(). This is in the W3C's DOM Level 1 ... always a good thing to use standards. Get the elements:
var headings1 = document.body.getElementsByTagName("H1");
Show the length:
alert(headings1.length);
Show the list:
for (var i = 0; i < headings1.length; i++) {
alert(headings1.childNodes[i].nodeValue);
}Wally Atkins
Newport News, VA, USA