...

View Full Version : change style to a group of elements



BubikolRamios
09-04-2008, 09:20 AM
at one point I do:


// if bla bla show one of elements
document.getElementById("textA").style.visibility = 'visible';


How to set back css state as declared in below css. The aim is to hide back all elemnts as they were at start. Don't like idea finding them by id ...

css


#columnA div div
{
visibility:hidden;
}




<div id = "columnA">
<div>
<div id = 'textA'>
some text
</div>
<div id = 'textB'>
some text
</div>
<div id = 'textX">
....
</div>
</div>
</div>

abduraooft
09-04-2008, 10:47 AM
One way is to loop through all div objects and set the style individually. Or assign a className to the div, say


document.getElementById("columnA").className = 'hidden';

div.hidden div div{
visibility:hidden;
}


<div id = "columnA" >
<div>
<div id = 'textA'>
some text
</div>
<div id = 'textB'>
some text
</div>
<div id = 'textX">
....
</div>
</div>
</div>
But this won't override the inline styles.

Kor
09-04-2008, 03:13 PM
Your case:


var divs=document.getElementById("columnA").getElementsByTagName('div')[0].getElementsByTagName('div'), i=0, d;
while(d=divs[i++]){
d.style.visibility='hidden';
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum