list - find the deepest LI in a lot of UL and LI using jquery -
so there tree. it's compiled mysql database using php. problem want find lis don't have ul inside them , more lis....
example: http://i.stack.imgur.com/pet8z.jpg
in example marked lis should selected jquery, because don't have children , that's want.
basically it's tree made categories, if deepest category doesn't have children should considered item , want jquery find items, don't have children.
this whole tree: http://jsfiddle.net/trueskillz/qnrpj/1/
i this(code down below) , check if has children or not , make it's background red(for example) , that's how find 'items' , not 'categories', there must easier way this....
$("#parttree ul").each(function(){ $(this).find("li").each(function(){ $(this).find("ul").each(function(){ $(this).find("ul").each(function(){ $(this).css("background-color","red"); }); }); }); });
this not way find items in list... i'm hoping there's easier way...
several options:
var $leaves = $('#parttree li').filter(function() { return !$(this).has('ul'); }); var $leaves = $('#parttree li:not(:has(ul))'); var $leaves = $('#parttree li').filter(":not(:has(ul))"); var $leaves = $('#parttree li').not(":has(ul)");
Comments
Post a Comment