Rem*_*emi 1 jquery this css-selectors jquery-selectors
我如何获得所有准备好的选定jquery元素内的所有链接(this)
$("#container li").each(function(){
$("this a").each(function(){
// links inside this li element
});
});
Run Code Online (Sandbox Code Playgroud)
这是行不通的另外一种方式吗?
你可以使用这个.find()功能:
$('#container li').each(function() {
$(this).find('a').each(function() {
// links inside this li element
});
});
Run Code Online (Sandbox Code Playgroud)
或者为了避免嵌套循环,您可以直接选择链接,然后li根据需要获取父级:
$('#container li a').each(function() {
var parentLi = $(this).parent('li');
});
Run Code Online (Sandbox Code Playgroud)