JavaScript
  Home arrow JavaScript arrow Page 4 - Opened and Closed Branches on a TreeView jQuery Hierarchical Navigation System
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
JAVASCRIPT

Opened and Closed Branches on a TreeView jQuery Hierarchical Navigation System
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 2
    2009-04-27


    Table of Contents:
  • Opened and Closed Branches on a TreeView jQuery Hierarchical Navigation System
  • Building basic hierarchical trees with the TreeView plug-in
  • Controlling the tree’s branches display with the closed CSS class
  • Collapsing tree branches with the TreeView plug-in

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Opened and Closed Branches on a TreeView jQuery Hierarchical Navigation System - Collapsing tree branches with the TreeView plug-in
    ( Page 4 of 4 )

     

    Provided that you already learned how to control the collapse and expansion of a tree’s branches using the “closed” CSS class, the last thing I’m going to cover in this tutorial will consist of replicating this process via the “collapsed” option provided by the “TreeView” plug-in. Basically, all that this option does is specify whether the mentioned branches will be displayed closed or opened initially. 

    A simple demonstration of how to use the “collapsed” argument is shown below. Check it out:

     

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

    <title>Example on jQuery TreeView (using collapsed option)</title>

    <link rel="stylesheet" href="jquery.treeview.css" type="text/css" />

    <script type="text/javascript" src="jquery.js"></script>

    <script type="text/javascript" src="jquery.treeview.js"></script>

    <script>

    // build treeview after web page has been loaded

    $(document).ready(function(){

    $("#menu").treeview({

    collapsed: true

    });

    });

    </script>

    </head>

    <body>

    <ul id="menu">

    <li>Link 1

    <ul>

    <li>Sub link 1</li>

    <li>Sub link 2</li>

    <li>Sub link 3</li>

    <li>Sub link 4</li>

    <li>Sub link 5</li>

    </ul>

    </li>

    <li>Link 2

    <ul>

    <li>Sub link 1</li>

    <li>Sub link 2</li>

    <li>Sub link 3</li>

    <li>Sub link 4</li>

    <li>Sub link 5</li>

    </ul>

    </li>

    <li>Link 3

    <ul>

    <li>Sub link 1</li>

    <li>Sub link 2</li>

    <li>Sub link 3</li>

    <li>Sub link 4</li>

    <li>Sub link 5</li>

    </ul>

    </li>

    <li>Link 4

    <ul>

    <li>Sub link 1</li>

    <li>Sub link 2</li>

    <li>Sub link 3</li>

    <li>Sub link 4</li>

    <li>Sub link 5</li>

    </ul>

    </li>

    <li>Link 5

    <ul>

    <li>Sub link 1</li>

    <li>Sub link 2</li>

    <li>Sub link 3</li>

    <li>Sub link 4</li>

    <li>Sub link 5</li>

    </ul>

    </li>

    </ul>

    </body>

    </html>

     

    As you can see, using the “collapsed” parameter to control how the branches of the tree will be shown in their initial state is really easy to grasp. For the example coded before, the argument simply specifies that all of the branches will be displayed closed, since a value of FALSE has been assigned to it. 

    The following image illustrates the behavior of the previous hierarchical tree more clearly, when using the “collapsed: false” option:

     

     

    Here you have it. At this time you should feel pretty satisfied, since you learned how to control, with a single option of the TreeView plug-in, the display of the tree’s branches. As I said before, this last example is the epilogue for this tutorial, so feel free to edit all of the code samples included in it to improve your skills with this powerful jQuery plug-in.

    Final thoughts 

    In this second episode of the series, I discussed the use of the “collapsed” option provided by the “TreeView” plug-in for controlling in one single step whether or not the branches of a specific tree will be displayed closed initially. 

    In the next part, things will become even more interesting. You’ll learn how to apply a really neat animation effect to a specific tree when expanding and collapsing its branches. Don’t miss the upcoming article! 



     
     
    >>> More JavaScript Articles          >>> More By Alejandro Gervasio
     

       

    JAVASCRIPT ARTICLES

    - Introduction to JavaScript
    - Adding Elements to a Tree with TreeView jQue...
    - Using the Persist Argument in a TreeView jQu...
    - Using Unique and Toggle in a TreeView jQuery...
    - Using Event Delegation for Mouseover Events ...
    - Using the Animate Option in a Treeview jQuer...
    - Using HTML Lists with Event Delegation in Ja...
    - Opened and Closed Branches on a TreeView jQu...
    - Mouseover Events and Event Delegation in Jav...
    - Creating a TreeView JQuery Hierarchical Navi...
    - Event Delegation in JavaScript
    - A Look at the New YUI Carousel Control
    - Working with Draggable Elements and Transpar...
    - Displaying Pinned Handles with Resizable Con...
    - Building Resizable Containers with the Ext J...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek