PDA

View Full Version : getElementById and visibility issue


coonbri
05-10-2005, 06:46 PM
I am trying to loop through the ID's from the DIV's to toggle visibility on and off. The first time through my loop the visibility property returns null.

Is there a known issue with Javascript and the visibility property?

The code is like this:
for(i = 1; i <= 3; i++)
{
if (document.getElementById('t' + i).style.visibility == 'visible')
{
document.getElementById('t' + i).style.visibility = 'hidden';
}

<STYLE TYPE="text/css">
<!--
#t1
{
position: absolute;left: 100px; top: 80px; height: 400px; width: 100px; z-index:1; visibility:visible; }

#t2
{
position: absolute;left: 100px; top: 80px; height: 400px; width: 100px; z-index:2; visibility:hidden; }

#t3
{
position: absolute;left: 100px; top: 80px; height: 400px; width: 100px; z-index:3; visibility:hidden; }
-->
</STYLE>


</head>
<body>
<form>
<div id="t1">Testimonial 1</div>
<div id="t2">Testimonial 2</div>
<div id="t3">Testimonial 3</div>

Thanks!!

Basscyst
05-10-2005, 07:13 PM
I think some properties can only be retrieved if they are set with inline styles or javascript initially. I could be wrong, and the reason for this I could not say, but I've had a similar issue before.

Basscyst

coonbri
05-10-2005, 07:31 PM
Bass player eh?

MikeFoster
05-10-2005, 07:37 PM
This is a simple article (http://cross-browser.com/talk/wheres_my_style.php) but it briefly summarizes the issue.