ok, see this code
<p>This is question 1.</p>
<img src="http://cliparts.co/cliparts/qTB/5yd/qTB5ydpzc.gif" alt="show answer" height="42" width="42" onclick="toggleAnswer(1)">
<p id="1">This answer1.</p>
<p>This is question 2.</p>
<img src="http://cliparts.co/cliparts/qTB/5yd/qTB5ydpzc.gif" alt="show answer" height="42" width="42" onclick="toggleAnswer(2)">
<p id="2">This answer2.</p>
<script type="text/javascript">
function toggleAnswer(no){
if (document.getElementById(no).style.display=="none")
{
document.getElementById(no).style.display="block";
}
else
{
document.getElementById(no).style.display="none";
}
}
</script>
The code means that there are many questions and if we click on the image next to a specific question the answer will appear accordingly.
Now, I want to make a button "show All" & "close ALL". WHen people click "show All" it will show all answers and when clicking "close ALL", it will close all answers.
My question is that
Is there anyway to force all elements inside a page to have style of either "block" or "none" without going through a loop?