Jquery 获取 this 或 $(this) 内的所有...

标签 jquery jquery-selectors css-selectors this

我怎样才能获得例如所有准备好的选定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/

相关文章:

php - AJAX 没有显示来自服务器请求的数据

父元素具有特定类的子元素的 CSS 选择器

css-selectors - 相当于 playwright 中的 by.name 选择器

css - Cypress 将鼠标悬停在名为 "Automation"的菜单选项上

jquery - jquery 正则表达式选择器如何工作?

jquery - 从一个 css 中的 for 循环生成的页面的不同背景

javascript - Uncaught Error : Bootstrap's JavaScript requires jQuery

jquery - 为什么这个 jQuery 选择器这么慢?

javascript - 如何使用 jQuery 将单击时 div 的位置更改为父 div 的中心?

jquery - 嵌套 Jquery 选择器