Add/Remove Items

You can add/remove items to the sidebar during the run time. The library will automatically refresh the portion of the sidebar that needs rebuilding. The example below demonstrates this feature.
$(function () { $('#sidebar').w2sidebar({ name: 'sidebar', nodes: [ { id: 'level-1', text: 'Level 1', img: 'icon-folder', expanded: true, group: true, nodes: [ { id: 'level-1-1', text: 'Level 1.1', icon: 'fa-star-empty' }, { id: 'level-1-2', text: 'Level 1.2', icon: 'fa-star-empty' }, { id: 'level-1-3', text: 'Level 1.3', icon: 'fa-star-empty' } ] } ] }); }); function addItems() { w2ui.sidebar.add([ { id: 'new-1', text: 'New Item 1', img: 'icon-add' }, { id: 'new-2', text: 'New Item 2', img: 'icon-add' }, { id: 'new-3', text: 'New Item 3', img: 'icon-add' } ]); } function insertItems() { w2ui.sidebar.insert('level-1-2', null, [ { id: 'new-4', text: 'New Item 4', img: 'icon-add' }, { id: 'new-5', text: 'New Item 5', img: 'icon-add' }, { id: 'new-6', text: 'New Item 6', img: 'icon-add' } ]); w2ui.sidebar.expand('level-1-2'); } function removeItem() { w2ui.sidebar.remove('new-1', 'new-2', 'new-3', 'new-4', 'new-5', 'new-6'); }