Hi all,
I've put together a page which has a series of hidden DIVS. When a user clicks a button, the DIV becomes visible. When they click the button again, it hides the DIV once more. That works, but I want to create another button which toggles all such DIVs on the page.
This is the function:
function expandcontent(cid) {
if (typeof ccollect!="undefined") {
if (collapseprevious=="yes")
contractcontent(cid)
document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none"
}
}
I call the function in this way:
<a href="javascript:expandcontent('hidden_IM01');expandcontent('hidden_IM02');expandcontent('hidden_IM03');" >Expand / collapse all articles</a>
My HTML looks like this:
<a href="javascript:expandcontent('hidden_IM01')">Expand / collapse article</a>
<div id="hidden_IM01" class="switchcontent">
<p>The content here</p>
</div>
With around 30 hidden DIVs per page, this is a rather cumbersome method. The ID of each hidden DIV begins with "hidden_", so I want to automatically find all of these DIVs, rather than having to manually go through my code and add each ID to the link.
Logically, this is how I think a solution might work:
Find all DIVs with the "switchcontent" class
Within that array, find all ID's beginning with "hidden_"
Call expandcontent() for each iteration
Can anybody help me with this? I'm a novice with javascript (I can modify code but not really write it). Any assistance would be greatly appreciated. Thanks!