View Full Version : Expanding Div Problem

09-10-2008, 03: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 = '';

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>

I hope you can help,
Many Thanks

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

that'll have the myvar id hidden by default

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