Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/weisjohn/jquery-tree-manipulator

A depth-first walker for manipulating an arbitrary DOM tree.
https://github.com/weisjohn/jquery-tree-manipulator

Last synced: about 1 month ago
JSON representation

A depth-first walker for manipulating an arbitrary DOM tree.

Awesome Lists containing this project

README

        

jquery-tree-manipulator
=============

a depth-first walker for manipulating an arbitrary DOM tree

`jquery-tree-manipulator` was born out of a need to integrate with http://blog.yesmeck.com/jquery-jsonview/ without rebuilding the whole thing.

[Demo](http://weisjohn.github.io/jquery-tree-manipulator/)

### usage

`sample.html`:

```html




  • foo


  • -
    bar

    • bat

    • baz

    • bin

    • -

      • cat






```

`sample.js`:

```javascript
$(".tree").treeManipulator({
structure: "> ul > li",
opened: ".collapser:contains('-')",
closed: ".collapser:contains('+')"
});
```

`jquery-tree-manipulator` requires you tell it how to traverse your tree. You must provide three selectors for it to know how to traverse, open, and close the DOM nodes.

You can then invoke the `close` and `open` methods on the plugin, optionally passing a `depth` limit as an argument, such as:

```javascript
// close all nodes
$(".tree").treeManipulator('close');
// open the first level
$(".tree").treeManipulator('open', 1);
```