Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-20-2012, 01:07 AM   PM User | #1
laffytaffykidd
New to the CF scene

 
Join Date: Sep 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
laffytaffykidd is an unknown quantity at this point
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>
laffytaffykidd is offline   Reply With Quote
Old 09-20-2012, 03:16 AM   PM User | #2
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 453 Times in 451 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
Looks ok as far as you've got. What's the problem?
xelawho is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:15 PM.


Advertisement
Log in to turn off these ads.