Please help with a hiding DIV problem

C

Chris Hughes

I have a routine that creates a page with 2 sets of tables with divs around
them.

Each div tag has a name.
The first set of tags are as follows
div id="T123" STYLE="display: none;">
div id="T113" STYLE="display: none;">
etc

I want to hide only the divs that start with T as I have others on the page
that I do not want to hide

Can someone please tell me how to do this??

Many Thanks

Chris
 
S

steve stevo

You will need to run a loop of all layers on the page,

for each layer get the id and test to see if there is a T within the id
(indexof)

then test to see if the T is the start of id (indexof again)

then if true hide the layer

Hope this Helps

Simon Christie
 
E

Evertjan.

Chris Hughes wrote on 21 okt 2003 in comp.lang.javascript:
I have a routine that creates a page with 2 sets of tables with divs
around them.

Each div tag has a name.
The first set of tags are as follows
div id="T123" STYLE="display: none;">
div id="T113" STYLE="display: none;">
etc

I want to hide only the divs that start with T as I have others on the
page that I do not want to hide

Can someone please tell me how to do this??

solution 1:
do not add STYLE="display: none;" to the second set.

solution 2:
add class: <div class="T" and <div class="nonT"

solution 3: NOT TESTED !!! [IE only code]
var coll = document.all.tags("DIV");
if (coll!=null)
for (i=0; i<coll.length; i++)
if(coll.id.substr(1)!="T")
coll.style.display = "block"
else
coll.style.display = "none"
 
L

Lasse Reichstein Nielsen

Chris Hughes said:
I have a routine that creates a page with 2 sets of tables with divs around
div id="T123" STYLE="display: none;"> ....
I want to hide only the divs that start with T as I have others on the page
that I do not want to hide

You can go through the divs one by one:

var divs = document.getElementsByTagName("div");
for (var i=0;i<divs.length;i++) {
if (divs.id.charAt(0)=="T") {
divs.style.display = "none";
}
}

/L
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top