TheCandyman
Technical User
I'm trying to loop though a few Div's and set them to hidden/visible. I have tried this a few ways but can't seem to get a winning solution as both of my try's show errors.
In the body:
In the head, try #1:
Error: object is null
object.style.display = 'none';
In the head, try #2:
Error: document.getElementById("Group" + i) is null
document.getElementById('Group'+i).style.display= 'none';
If i do this it works, but it can get pretty large so i'd rather do the loops above:
In the body:
Code:
<div id="Group1" style="display:none;">
<p>Question 1</p>
<p>Question 2</p>
<p>Question 3</p>
</div>
...
...
<div id="Group6" style="display:none;">
<p>Question 7</p>
<p>Question 7</p>
<p>Question 7</p>
</div>
In the head, try #1:
Code:
for (i=1; i<=7; i++)
{
object = document.getElementById('Group' + i);
object.style.display = 'none';
}
object.style.display = 'none';
In the head, try #2:
Code:
for (i=1; i<=7; i++)
{
document.getElementById('Group'+i).style.display= 'none';
}
document.getElementById('Group'+i).style.display= 'none';
If i do this it works, but it can get pretty large so i'd rather do the loops above:
Code:
document.getElementById('Group1').style.display= 'none';
document.getElementById('Group2').style.display= 'none';
document.getElementById('Group3').style.display= 'none';
document.getElementById('Group4').style.display= 'none';
document.getElementById('Group5').style.display= 'none';
document.getElementById('Group6').style.display= 'none';