Forum Moderators: open
Here is the code:
Swaps the "active" tab and "inactive" tab and swaps out the new content via the display style attribute:
var active = 1;
var d = document;
function swapDiv(n) {
if (n != active) {
//tabs
d.getElementById("l"+n).className = "active"
d.getElementById("l"+active).className = "inactive";
//divs
d.getElementById("d"+n).style.display = "block";
d.getElementById("d"+active).style.display = "none";
//set active
active = n;
//even divs
evenDivs();
}
}
The evenDivs() function which is the problem area. As I said, I want the two divs to have the same height, but I would like the "content" div to be able to shrink or expand to fit the content.
function evenDivs() {
var l = d.getElementById("content");
var r = d.getElementById("right");
//reset div heights
l.style.height = "";
r.style.height = "";
//check and resize divs as necessary
if (parseInt(l.offsetHeight) > parseInt(r.offsetHeight)) {
r.style.height = (parseInt(l.offsetHeight)+23)+"px";
} else if (parseInt(l.offsetHeight) < parseInt(r.offsetHeight)); {
l.style.height = (parseInt(r.offsetHeight)-27)+"px";
}
And finally the HTML:
<div id="left">
<ul class="nav">
<li class="active" id="l1"><a onclick="swapDiv(1)">How this works</a></li>
<li class="inactive" id="l2"><a onclick="swapDiv(2)">About Us</a></li>
<li class="inactive" id="l3"><a onclick="swapDiv(3)">Testimonials</a></li>
<li class="inactive" id="l4"><a onclick="swapDiv(4)">Contact Us</a></li>
</ul>
<div class="clear"> </div>
<div id="content">
<div id="d1" class="content">
<h3>How it works</h3>
</div>
<div id="d2" class="content" style="display:none;">
<h3>About US</h3>
</div>
<div id="d3" class="content" style="display:none;">
<h3>Testimonials</h3>
</div>
<div id="d4" class="content" style="display:none;">
<p>Contact Us Info</p>
</div>
</div>
</div>
[edited by: Randomgnome at 1:01 am (utc) on June 10, 2009]
Also, have you tried using straight CSS for this? Put both divs in another, give 'right' 100% height, and let 'content' determine what the height is. It might not work but, again, you never know.