Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Sep 2012
    Thanked 0 Times in 0 Posts

    Iterating through HTML using the DOM

    I am trying to iterate through the DOM of my document using javascript, but I am unsure about how to start.

    I assume my js file should be something like this, but I'm just not sure how to get it working... can someone point me in the right direction?

    var all = document.getElementsByTagName("*");
    for (var i=0, max=all.length; i < max; i++) {
         // Do something with the element here
    Below is my HTML code.. very basic coding as you can tell.
    <link rel="stylesheet" type="text/css" href="lab2.css" />
    <h1> First Song </h1>
          <p class="small"> Make You Wonna </p>
          Jakebeatz & Jay-Rock
          <p class="italic"> Power to the B-Boyz </p>
          <img src="make you wonna.jpg" />
          <p class="scale"> 9/29/91 </p>
          <p class="scale"><li> Electronic </li></p>
          <a href="www.jay-roc.com" > Jay Roc </a>
    <h2> Second Song </h2>
          <p class="small"><Good Life </p>
          <p class="italic"> Waking Up </p>
          <img src="good life.jpg" />
          <p class="scale"> 9/29/91 </p>
          <p class="scale"><li> Pop </li></p>
          <a href = "www.onerepublic.net" > one </a>
    <h3> Third Song </h3>
          <p class="small"> Fall For You </p>
          Secondhand Serenade
          <p class="italic"> A Twist in My Story </p>
          <img src="fall for you.jpg" />
          <p class="scale"> 9/29/91 </p>
          <p class="scale"><li> Alternative </li></p>
          <a href = "www.secondhandserenade.net" > secondhand </a>
    <h4> Fourth Song </h4>
          <p class="small"> Moves Like Jagger </p>
          Maroon 5
          <p class="italic"> Hands All Over </p>
          <img src="m.jpg </li>
          <p class="scale"> 9/29/91 </p>
          <p class="scale"><li> Pop </li></p>
          <a href = "www.maroon5.com" > maroon </a>
    <script src="lab3.js">

  2. #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Thanked 601 Times in 597 Posts
    Looks ok as far as you've got. What's the problem?


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts