开发者

Jquery get all ... inside this or $(this)

how can i get for example all links inside a all ready selected jquery element (this)

$("#cont开发者_如何学Pythonainer li").each(function(){
   $("this a").each(function(){
      // links inside this li element
   });
});

This does not work is there a other way?


You could use the .find() function:

$('#container li').each(function() {
    $(this).find('a').each(function() {
        // links inside this li element
    });
});

or to avoid nested loops you could directly select the links and then fetch the parent li if needed:

$('#container li a').each(function() {
    var parentLi = $(this).parent('li');
});


Alternatively to Darin's proposal, jQuery allows you to define a context node for a selector.

So, you could do this:

var
  $listItems = $('#container li'),
  // use $listItems as context
  $anchors = $('a', $listItems);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜