473,386 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Expanding / Collapse specific div tags

Tim
hi all,

Im just starting to get into javascript, and what I am trying to do is
find a script that I can run on page load that will collapse / hide all
div tages that have an id that begins with "div_".

Basically I have a page with an infinite amount of div tags each having
their own id, ie div_0 , div_1 etc etc ..

on page load i want them all closed, but only these ones . not any
other div on the page .. how would I be able to do this ..

any help greatly appreciated ..

thanks

tim

May 29 '06 #1
2 3389
Ivo

"Tim" <ti*****@gmail.com> schreef in bericht
news:11**********************@u72g2000cwu.googlegr oups.com...
hi all,

Im just starting to get into javascript, and what I am trying to do is
find a script that I can run on page load that will collapse / hide all
div tages that have an id that begins with "div_".

Basically I have a page with an infinite amount of div tags each having
their own id, ie div_0 , div_1 etc etc ..

on page load i want them all closed, but only these ones . not any
other div on the page .. how would I be able to do this ..

any help greatly appreciated ..

thanks

tim


Put all div elements in an array and loop through that array, checking every
element's id as you go. For example like this:

function hidedivs() {
var els = document.getElementsByTagName( 'div' );
var num = els.length;
for( var i = 0; i<num; i++ ) {
if( els[i].id.indexOf( 'div_' )===0 ) {
els[i].style.display = 'none';
}
}
}
window.onload = hidedivs;

hth
ivo
http://4umi.com/web/javascript/
May 29 '06 #2
Tim
perfect .. thanks ! D

May 30 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Vegard Beider | last post by:
This works fine in Opera and IE, but in Firefox 1.0 there seems to be a problem. With border-collapse set to collapse, it indents the table 1px to the left. Any ideas how to resolve this without...
3
by: ireneatngs | last post by:
Hi, I have example html below which contains a couple of hidden divs. However, some of the table borders within these hidden divs are actually displayed when they should not be. In my...
4
by: Alvaro G Vicario | last post by:
I have a list built on HTML and CSS: <ul> <li>Foo</li> <li>Bar <ul> <li>Gee</li> </ul> </li> </ul>
6
by: Jack | last post by:
Hello, I would like some advice on how to disable the behavior of treeviews to expand and collapse when double clicked upon, but still allow the user to use the plus and minus on each node. ...
26
by: JJ | last post by:
Is there any way you can expand a parent node on the treeview control _without a postback_ by clicking on the node text (NOT clicking the expand image URL) ? I want to format the treeview node...
13
Chrisjc
by: Chrisjc | last post by:
I am in need of an expanding and collapsing code… The goal is To be able to click a PICTURE IMAGE and expand to show information Reason for this is I have 3 TABLES of information of about ...
3
by: Max58kl | last post by:
Hi I am currently trying to create a FAQ webpage. At the moment the code I have lets me click on the Questions which successfully shows and hides the <DIV> tags containing the Answers. But...
1
by: Jahedx99 | last post by:
Check out the site: www.progtalk.com. They have a great article to expand and collapse rows of a grid. The cool part it, that the expanding and collapsing happens using Javascript. I think the...
4
by: Sean | last post by:
Hi, all, In a table I can easily get those expanding nodes (+ and - signs) to expand/collapse subdatasheets. How can I get those in forms? Thanks, Sean
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.