1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to make - When you click on a menu item, the list remained open?

Discussion in 'HTML & JavaScript' started by barigain, Jan 3, 2014.

  1. barigain

    barigain Junior Member

    Joined:
    Aug 23, 2012
    Messages:
    100
    Likes Received:
    12
    Dear Webmasters, I can not deal with javascript, generally need to the menu when you click on the item subcategories remained open after the transition this category which crossed. To keep open the list, and I get it when going slams, here's the code:


    tags in the head:
    code:
    Code:
    <style type="text/css">
    ol {display:none;}
    </style>
    
    
    <script type="text/javascript">
    function shouNone(el){
    var s;
    el=el.getElementsByTagName("ol")[0].style;
    s=el.display;
    if(s=="none"||s==""){el.display="block";}
    else{el.display="none";};
     };
    </script>

    the menu itself:
    Code:
    <li class="catsub" onclick="shouNone(this);" ondblclick="location.href='http://site.com/cat1.html'">
                <a href="javascript:void(0)">Cat 1</a>
                <ol class="catsubhref">
                    <a href="/price/cat1/1/">Page 1</a>
                    <a href="/price/cat1/2/">Page 2</a>
                    <a href="/price/cat1/3/">Page 3</a>
                </ol>
            </li>
    <li class="catsub" onclick="shouNone(this);" ondblclick="location.href='http://site.com/cat2.html'">
                <a href="javascript:void(0)">Cat 2</a>
                <ol class="catsubhref">
                    <a href="/price/cat2/1/">Page 1</a>
                    <a href="/price/cat2/2/">Page 2</a>
                    <a href="/price/cat2/3/">Page 3</a>
                </ol>
            </li>
    How to implement javascript?
    Thanks!
     
  2. funque

    funque Newbie

    Joined:
    Dec 27, 2013
    Messages:
    21
    Likes Received:
    1
    You can do it through cookies.
    I do so sometimes. page content is assigned to a thread or a custom attribute class. and then starting from this value is made active the desired menu item.
     
  3. barigain

    barigain Junior Member

    Joined:
    Aug 23, 2012
    Messages:
    100
    Likes Received:
    12
    What do you mean? How can I use cookies in Javascript for this page?..
     
  4. mindlesswizard

    mindlesswizard Supreme Member

    Joined:
    Sep 3, 2010
    Messages:
    1,368
    Likes Received:
    289
    Occupation:
    Designer/Developer, Internet Marketer
    Location:
    in the shade of Everest
    I would never use js with the menus ! Specially inside the html tags ! :/
     
  5. funque

    funque Newbie

    Joined:
    Dec 27, 2013
    Messages:
    21
    Likes Received:
    1
    JavaScript can create cookies, read cookies, and delete cookies with the property document.cookie.
    With JavaScript, a cookie can be created like this:

    Code:
    document.cookie="username=John Doe";
    You can alo add an expiry date (in UTC or GMT time). By default, the cookie is deleted when the browser is closed:

    Code:
    document.cookie="username=John Doe; expires=Thu, 18 Dec 2013 12:00:00 GMT";
    With a path parameter, you can tell the browser what path the cookie belongs to. By default, the cookie belongs to the current page.

    Code:
    document.cookie="username=John Doe; expires=Thu, 18 Dec 2013 12:00:00 GMT;" path=/";