Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,963
    Thanks
    120
    Thanked 76 Times in 76 Posts

    change style to a group of elements

    at one point I do:
    Code:
    // 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
    Code:
    #columnA div div
    {
      visibility:hidden;
    }
    Code:
    <div id = "columnA">
      <div>
         <div id = 'textA'>
           some text
         </div>
         <div id = 'textB'>
           some text
         </div>
         <div  id = 'textX">
           ....
         </div>
      </div>
    </div>

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,862
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    One way is to loop through all div objects and set the style individually. Or assign a className to the div, say

    Code:
    document.getElementById("columnA").className = 'hidden';
    Code:
    div.hidden div div{
    visibility:hidden;
    }
    Code:
    <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.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Your case:
    Code:
    var divs=document.getElementById("columnA").getElementsByTagName('div')[0].getElementsByTagName('div'), i=0, d;
    while(d=divs[i++]){
    d.style.visibility='hidden';
    }
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •