Donno24
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 = '';
}
}
//-->
</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
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