Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Javascript/DOM

Javascript/DOM

Scheduled Pinned Locked Moved Web Development
htmljavascripttutorialquestionannouncement
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    andyg 101
    wrote on last edited by
    #1

    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; i

    to 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

    D 1 Reply Last reply
    0
    • A andyg 101

      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; i

      to 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

      D Offline
      D Offline
      DFU23
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups