CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   DOM and JSON scripting (http://www.codingforums.com/forumdisplay.php?f=15)
-   -   Iterating through HTML using the DOM (http://www.codingforums.com/showthread.php?t=273625)

laffytaffykidd 09-20-2012 01:07 AM

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?

Code:

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.
Code:

<html>
<head>
<link rel="stylesheet" type="text/css" href="lab2.css" />
</head>

<body>

<h1> First Song </h1>

  <ul>
      <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>
  </ul>

<h2> Second Song </h2>
  <ul>
      <p class="small"><Good Life </p>
      Onerepublic
      <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>
  </ul>

<h3> Third Song </h3>
  <ul>
      <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>
  </ul>

<h4> Fourth Song </h4>
  <ul>
      <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>
  <ul>


<script src="lab3.js">
</script>

</body>
</html>


xelawho 09-20-2012 03:16 AM

Looks ok as far as you've got. What's the problem?


All times are GMT +1. The time now is 11:19 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.