Is it possible to apply the javascript to multiple divs with the same id? At the moment it only applies it to the first found, I guess at [0]. Is it possible to loop through the divs and apply it that way?
<body>
<div id="mainHolder">
<div id="header">
<img src="images/collapse1.png" />
</div>
<div id="content">
<p>This is a collapsible panel</p>
<img src="images/bird.jpg" height="130"/>
</div>
</div>
<div id="panelBelow">
<p>A panel is placed below the collapsible panel, just to show that when the panel above collapses the panel below is also moved up.</p>
</div>
<br></br>
<div id="mainHolder">
<div id="header">
<img src="images/collapse1.png" />
</div>
<div id="content">
<p>This is a collapsible panel</p>
<img src="images/bird.jpg" height="130"/>
</div>
</div>
</body>
<script type="text/javascript">
var header = null;
var content = null;
var mainHolder = null;
var expandCollapseBtn = null;
var heightValue = 0;
header = document.getElementById("header");
content = document.getElementById("content");
mainHolder = document.getElementById("mainHolder");
expandCollapseBtn = header.getElementsByTagName('img')[0];
heightValue = mainHolder.offsetHeight;
header.addEventListener('click', handleClick, false);
mainHolder.addEventListener('webkitTransitionEnd',transitionEndHandler,false);
function handleClick()
{
if(expandCollapseBtn.src.search('collapse') !=-1)
{
mainHolder.style.height = "30px";
content.style.display = "none";
}
else
{
mainHolder.style.height = heightValue + "px";
}
}
function transitionEndHandler()
{
if(expandCollapseBtn.src.search('collapse') !=-1)
{
expandCollapseBtn.src = "images/expand1.png";
}
else{
expandCollapseBtn.src = "images/collapse1.png";
content.style.display = "block";
}
}
</script>