Takes an item in a series of nested HTML lists and gives you full path to item.
getListItemPath = require('getListItemPath');
getListItemPaths = require('getListItemPaths');
var selected = '[selected=selected]';
var tree = 'ul';
var joinPathBy = '/';
var joinPathsBy = ', ';
var firstPathString = getListItemPath(tree, $(selected).first(), undefined, joinPathBy));
var allPathsString = getListItemPaths(tree, selected, undefined, joinPathBy, joinPathsBy));
var selected = '[selected=selected]';
var tree = 'ul';
var joinBy = '/';
var firstPathArr = getListItemPath(tree, $(selected).first());
var firstPathString = firstPathArr.join(joinBy);
var selected = '[selected=selected]';
var tree = 'ul';
getListItemPaths(tree, selected).forEach(function (path) {
//do something with each path individually
});
var selected = '[selected=selected]';
var tree = 'ul';
var joinPathBy = '/';
var joinPathsBy = ', ';
var selectedPaths = getListItemPaths(tree, selected);
var selectedPathsString = $.map(selectedPaths, function(path){
return path.join(joinPathBy);
}).join(joinPathsBy);
Start the sample app:
node tests/app.js
Open up the sample page: