我怎样才能获得例如所有准备好的选定jquery元素内的所有链接(这个)
$("#container li").each(function(){
$("this a").each(function(){
// links inside this li element
});
});
这不起作用,还有其他方法吗?
最佳答案
您可以使用.find()
功能:
$('#container li').each(function() {
$(this).find('a').each(function() {
// links inside this li element
});
});
或者为了避免嵌套循环,您可以直接选择链接,然后根据需要获取父li
:
$('#container li a').each(function() {
var parentLi = $(this).parent('li');
});
关于Jquery 获取 this 或 $(this) 内的所有...,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3838172/