...

View Full Version : Expanding Div Problem



Donno24
09-10-2008, 04:05 PM
Hi Everyone, I have this simple javascript which is meant to expand and collapse a div when clicking on a link.

The problem i am having is that on page load the javascript expands the div which I do not want, what I want is it to be closed until the user clicks on the link.

Here is the javascript

<script type="text/javascript">
<!--
function switchMenu(obj) {
var el = document.getElementById(obj);
if ( el.style.display != "none" ) {
el.style.display = 'none';
}
else {
el.style.display = '';
}
}
//-->
</script>

here is the HTML



<div id="wrapper">
<p><a onclick="switchMenu('myvar');" title="Switch the Menu">More Info...</a></p>
<div id="myvar">
<p>This is paragraph text </p>
<p>This is paragraph text </p>
<p>This is paragraph text </p>
<p>This is paragraph text </p>
</div>
</div>

I hope you can help,
Many Thanks
Donno24

ohgod
09-10-2008, 04:33 PM
<div style="display:none;" id="myvar">

that'll have the myvar id hidden by default

Donno24
09-10-2008, 04:35 PM
Aha, perfect! Thanks Alot.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum