HOW??? - Loop through <div> elements on page

This is a discussion on "HOW??? - Loop through <div> elements on page" within the JavaScript Forum section. This forum, and the thread "HOW??? - Loop through <div> elements on page are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Closed Thread
 
LinkBack Thread Tools
  #1 (permalink)  
Old Aug 22nd, 2007, 17:56
Junior Member
Join Date: Feb 2007
Location: USA
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Question HOW??? - Loop through <div> elements on page

On one of my pages I used javascript to run through each checkbox element on the page and based on the value attribute it would disable or enable it.
Sort of like this :
Code: Select all
for(var i=0; i<document.formname.elements.length; i++) {
    if(document.formname.elements[i].value == "bluecheckbox") {
       if(document.formname.elements[i].disabled == true) {
         //enable it
      }
   }//outer if
}//for
<div>'s can't be accessed in a way similar to my code snippet above.

What javascript code do I use to loop through the <div>'s? I only want to hide the <div>'s that have their id attribute set to a specific set of letter's...how can I do that?

Edited at 3:24 p.m....Reason - Problem Solved!
I did some googling, then some testing, and arrived at the following code, which takes care of my issue, so here it is for everyone else too!
Code: Select all
var divs = document.getElementsByTagName('div');
for (var i = 0; i < divs.length; i++){                      
      var divname = divs[i].id; 
      if(divname.indexOf("sometext") == 0) { 
        //yes it is, do something
      }//if
}//for


Last edited by Daniel; Aug 22nd, 2007 at 21:59. Reason: Solved problem before anyone posted a reply...

  #2 (permalink)  
Old Aug 22nd, 2007, 21:59
Daniel's Avatar
Elite Veteran
Join Date: Sep 2006
Location: The Kingdom of Rabbits
Age: 21
Posts: 2,051
Blog Entries: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Daniel
Re: HOW??? - Loop through <div> elements on page

Woo go you!!

Thread closed.
Last Blog Entry: Assassin's Creed (Nov 22nd, 2007)
Closed Thread

Tags
loop through divs

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Do a while loop once? Jack Franklin PHP Forum 2 Feb 15th, 2008 11:07
The Loop (Again) Blake121 Free Web Site Critique 16 Sep 7th, 2007 13:57
The Loop V2 Blake121 Free Web Site Critique 8 May 15th, 2007 09:37
The Loop Blake121 Free Web Site Critique 5 May 1st, 2007 14:25
Loop??? tazek0 Classic ASP 0 Jan 27th, 2006 07:38


All times are GMT. The time now is 10:21.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43