开发者

loop through list with sublists javascript

ul li1 li2 ul3 li3.1 li3.2 ul3.3 开发者_Go百科 ul3.3.1 ul3.3.2 li4 li5

and I must check all items in ul3 I can't be sure if there is only two or three or more lists


Well, I don't know what you mean by "check", but you can have a function be called for each <li> like this:

$('li').each(function() {
  // whatever "check" means
});

With just plain Javascript:

var nodes = document.getElementsByTagName('li');
for (var i = 0; i < nodes.length; ++i) {
  var li = nodes[i];
  // check ...
}

edit — well it's not clear what exactly you need, but if you just need to inspect <li> elements in lists that are themselves in <li> elements, then you'd just code that into the jQuery selector:

$('ul ul li').each(function() { ... });


Use the each() like this:

$('ul li').each(function(){
  // your code.....
});

This will loop through the ul children at any nested level.

Update:

and I must check all items in ul3 I can't be sure if there is only two or three or more lists

Try this in that case:

$('ul:eq(2) li').each(function(){
  // your code.....
});

This will start from third ul and find its children at any nested level.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜