Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Mar 2008
    Location
    Co.Tyrone, Ireland
    Posts
    80
    Thanks
    8
    Thanked 1 Time in 1 Post

    Expanding Div Problem

    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
    Code:
    <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

    Code:
    <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

  • #2
    Regular Coder ohgod's Avatar
    Join Date
    Jun 2008
    Location
    Ohio
    Posts
    579
    Thanks
    6
    Thanked 69 Times in 69 Posts
    Code:
    <div style="display:none;" id="myvar">
    that'll have the myvar id hidden by default

  • #3
    New Coder
    Join Date
    Mar 2008
    Location
    Co.Tyrone, Ireland
    Posts
    80
    Thanks
    8
    Thanked 1 Time in 1 Post
    Aha, perfect! Thanks Alot.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •