Keep menu tree expanded after loading page

Discussion in 'JavaScript' started by braiiins, Apr 20, 2008.

  1. #1
    Is there a way to keep a menu tree expanded to the proper section after clicking a menu link and loading the page? For example, say I have this menu:

    one
    --one-a
    --one-b
    --one-c
    ----one-c-one
    ----one-c-two
    two
    --two-a
    --two-b

    ...etc

    If I click on one-c-one and load page one-c-one, I want the menu to stay expanded up to parent one-c. Is there a way to do this without using iframes?

    Here is my javascript:
    
    <script type="text/javascript">
    function handleParent(parentId)
    {
    	myParent = document.getElementById("menu" + parentId)
    
    	if (myParent.style.display=="none") {
    		myParent.style.display="block"
    	} else {
    		myParent.style.display="none"
    	}
    }
    </script>
    
    Code (markup):
    And a sample of my menu structure:
    
    <div id="storemenu">	
    
    	<menu id="booksandmovies">
    	<li><a href="javascript:handleParent(1)">Books &amp; Movies</a>
    	<menu id="menu1" style="display:none;">
    			<li><a href="javascript:handleParent(2)">Books</a>
    			<menu id="menu2" style="display:none;">
    				<li><a href="javascript:handleParent(3)">Food</a>
    				<menu id="menu3" style="display:none;">
    					<li><a href="<?php echo get_permalink(175); ?>">Cookbooks</a></li>
    					<li><a href="<?php echo get_permalink(176); ?>">Shopping</a></li>
    					<li><a href="<?php echo get_permalink(177); ?>">Gardening</a></li>
    					<li><a href="<?php echo get_permalink(174); ?>">Uncategorized</a></li>
    				</menu><!-- menu3 -->
    				</li>
    				<li><a href="<?php echo get_permalink(178); ?>">Baby</a></li>
    				<li><a href="<?php echo get_permalink(179); ?>">Kids Books</a></li>
    				<li><a href="<?php echo get_permalink(180); ?>">Entertainment</a></li>
    				<li><a href="<?php echo get_permalink(181); ?>">Health &amp; Beauty</a></li>
    				<li><a href="<?php echo get_permalink(182); ?>">Home</a></li>
    				<li><a href="<?php echo get_permalink(183); ?>">Pets</a></li>
    				<li><a href="<?php echo get_permalink(173); ?>">Uncategorized</a></li>
    			</menu><!-- menu2 -->
    			</li>
    			<li><a href="<?php echo get_permalink(184); ?>">Movies</a></li>
    	</menu><!-- menu1 -->
    	</li>
    	</menu><!-- booksandmovies -->
    
    Code (markup):
     
    braiiins, Apr 20, 2008 IP
  2. braiiins

    braiiins Guest

    Messages:
    23
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Anyone? I can't find information for how to make this work right.
     
    braiiins, Apr 27, 2008 IP