Skip to main content
deleted 82 characters in body; edited tags; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Jquery jQuery File Tree Toggle - Code Efficiency

I am making a web app that will have a "my files" area and to do so I am writing my own html and jQuery to control the opening and closing of each folder (or ul liul li). I want to make sure that this web app is as efficient as I can make it as it may have to deal with a large amount of hierarchy.

Can anyone suggest a way that my Jquery could be more efficient? Many thanksjsFiddle

JSFIDDLE

Jquery File Tree Toggle - Code Efficiency

I am making a web app that will have a "my files" area and to do so I am writing my own html and jQuery to control the opening and closing of each folder (or ul li). I want to make sure that this web app is as efficient as I can make it as it may have to deal with a large amount of hierarchy.

Can anyone suggest a way that my Jquery could be more efficient? Many thanks

JSFIDDLE

jQuery File Tree Toggle

I am making a web app that will have a "my files" area and to do so I am writing my own html and jQuery to control the opening and closing of each folder (or ul li). I want to make sure that this web app is as efficient as I can make it as it may have to deal with a large amount of hierarchy.

jsFiddle

Source Link
2ne
  • 209
  • 1
  • 10

Jquery File Tree Toggle - Code Efficiency

I am making a web app that will have a "my files" area and to do so I am writing my own html and jQuery to control the opening and closing of each folder (or ul li). I want to make sure that this web app is as efficient as I can make it as it may have to deal with a large amount of hierarchy.

Can anyone suggest a way that my Jquery could be more efficient? Many thanks

<!doctype html>
<html>
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width" />
        <title>Title</title>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
        <style>
            li {
                cursor: pointer;
                line-height: 20px;
                list-style: none;
            }
            li ul {
                display: none;    
            }
            .active {
                
            }
        </style>
    </head>
    <body>
        <div class="tree-wrapper">
            <ul class="tree">
                <li>
                    <a href="#">Animals</a>
                    <ul>
                        <li>
                            <a href="#">Birds</a>
                        </li>
                        <li>
                            <a href="#">Mammals</a>
                            <ul>
                                <li>Elephant</li>
                                <li>Mouse</li>
                            </ul>
                        </li>
                        <li>
                            <a href="#">Reptiles</a>
                        </li>
                    </ul>
                </li>
                <li><a href="#">Plants
                        <ul>
                            <li>
                                <a href="#">Flowers</a>
                                <ul>
                                    <li><a href="#">Rose</a></li>
                                    <li><a href="#">Tulip</a></li>
                                </ul>
                            </li>
                            <li><a href="#">Trees</a></li>
                        </ul>
                    </a>
                </li>
            </ul>
        </div>
        <script>
            var folderToggle = $(".tree li > a");   

            $(function () {
                folderToggle.click(function(e) {
                    e.preventDefault();
                    $(this).find("+ ul").toggle("slow");
                    $(this).toggleClass("active");
                });
            });
        </script>
    </body>
</html>

JSFIDDLE