Navigation Usability

  Home arrow Navigation Usability arrow Page 5 - Advanced Bulleted-List Menu
NAVIGATION USABILITY

Advanced Bulleted-List Menu
By: notepad
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2005-05-06

    Table of Contents:
  • Advanced Bulleted-List Menu
  • Menu Layout
  • Preserving State Without Cookies
  • Adding CSS
  • Adding JavaScript
  • Drawing Our Menu
  • Conclusion

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    Advanced Bulleted-List Menu - Adding JavaScript


    (Page 5 of 7 )

    For the JavaScript, all we need is a simple toggle function to hide or display content. Since this code is so small, I won't bother storing it in an external file. In fact, I think you'll get JavaScript errors if you try to store it in an external file anyway.

    <script type="text/javascript">
    <!--
    function toggle(id) {
      if(document.getElementById) {
        var el = document.getElementById(id);
        el.style.display = (el.style.display == 'none') ? 'block' : 'none';
      }
    }
    // -->
    </script>

    The function verifies the getElementById method exists so the script degrades nicely in older browsers. If everything is good, it uses the method to isolate the element passed to the function and toggles the display style associated with it.

    To implement a call to the JavaScript function, a set of div tags with an id attribute should wrap the stuff to toggle and the a tag’s onclick attribute should call the function. Calling the toggle function with that id effects whatever content is enclosed within the div.

    <div id="test">
    <a href="#" onclick="toggle('test');">hide me</a>
    </div>

    When the user clicks the link, our JavaScript toggle function will be called and change the div’s display style affecting the contents within it. Pretty nifty, aye?

    More Navigation Usability Articles
    More By notepad

    blog comments powered by Disqus

    NAVIGATION USABILITY ARTICLES

    - Advanced Bulleted-List Menu
    - Using Multiple Pages for Navigation

    Developer Shed Affiliates

     



    © 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap