Mini DropDown Menu

Discussion in 'JavaScript' started by reptile1903, Jul 16, 2010.

  1. #1
    Hello, i want to do own mini dropdown menu. I coded simple something.

    
    <script type="text/javascript">
    	var sit = 0;
    	function collapse() {
    		if (sit == 0) {
    			document.getElementById('submenu').style.visibility = 'visible';
    			document.getElementById('submenu').style.height = 'auto';
    			sit = 1;
    		}
    		else if (sit == 1) {
    			document.getElementById('submenu').style.visibility = 'hidden';
    			document.getElementById('submenu').style.height = '5px';
    			sit = 0;
    		}
    	}
    </script>
    <div><a href="#" onclick="collapse()">Cat 1</a></div>
    <div id="submenu" style="visibility: hidden; height:0px">
    SubCat 1<br>
    SubCat 2<br>
    SubCat 3<br>
    SubCat 4<br>
    SubCat 5<br>
    </div>
    <div>Cat 2</div>
    
    Code (markup):
    It works in Mozilla Firefox & Google Chrome but doesn't work IE7. How can i fix this problem ?

    Regards.
     
    reptile1903, Jul 16, 2010 IP
  2. Imozeb

    Imozeb Peon

    Messages:
    666
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Instead of .visibility try .display = 'none' and .display = ''
     
    Imozeb, Jul 16, 2010 IP
  3. reptile1903

    reptile1903 Member

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #3
    Problem isn't about visibility, it is height. Hiding element is working all browser but IE doesn't support <div id="submenu" style="visibility: hidden; height:0px"> statement.
     
    reptile1903, Jul 16, 2010 IP
  4. ashishhbti

    ashishhbti Peon

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If you will add visibility hidden then it hides the element, but it still takes up space in the layout. So try Display none ..

    In displa none you dont need to set height to 0 or 5px.
     
    ashishhbti, Jul 21, 2010 IP