It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

problem with retrieving a property

problem with retrieving a property

Postby MSBSpectator on Fri Feb 08, 2008 8:50 pm

hi

I'm trying to make a collapsible section in a webpage. Right now, all the code for it is working except for a check on style.visibility:
Code: Select all
if (document.getElementById(contentID).style.visibility == 'visible')
. I played around with it and was able to see that the first part of that if statment doesn't return anything. :?

Here's the script:
Code: Select all
function toggleCollapse(contentID, choiceID) {
   if (document.getElementById(contentID)) {
      if (document.getElementById(contentID).style.visibility == 'visible') {
         document.getElementById(contentID).style.height = 'auto';
         document.getElementById(contentID).style.visibility = 'visible';
         changeChoice(choiceID, true);
      }
   }
}

Here's the relevant CSS:
Code: Select all
.Dept_Collapsed {
   background-image: url(Files/Dept%20Expand.gif);
   width: 545px;
   height: 37px;
}
.Content_Collapsed {
   height: 0px;
   visibility: hidden;
}

Here's the body:
Code: Select all
<div id="1" class="Dept_Collapsed" onClick="toggleCollapse('2', '1')"></div>
<div id="2" class="Content_Collapsed">Test 2</div>


How do I fix it so I can compare if it's hidden or not:?:
MSBSpectator
 
Posts: 2
Joined: Fri Feb 08, 2008 8:38 pm

Postby MSBSpectator on Sun Feb 10, 2008 2:11 am

Nvm fixed it. Ironically found out the problem 5 min after I posted.
.style only gets the attribute if it is explicitly stated by an inline styles or by javascript

changed
Code: Select all
.style
to
Code: Select all
.currentStyle
MSBSpectator
 
Posts: 2
Joined: Fri Feb 08, 2008 8:38 pm


Who is online

Users browsing this forum: No registered users and 6 guests