【问题标题】:jQuery select all elements inside particular parent elementsjQuery选择特定父元素内的所有元素
【发布时间】:2012-11-08 00:37:38
【问题描述】:

我需要遍历所有表格元素,在某处保留索引,然后遍历这些表格中的所有元素。想法是将有关表内元素及其表索引的信息添加到数据库中。

【问题讨论】:

    标签: jquery css-selectors


    【解决方案1】:
    $('table').each(function(index) {
        $(this).find('*').each(function() {
            /* do magic */
        });
    });
    

    【讨论】:

      【解决方案2】:

      只需使用 children() 选择父级的所有元素:

      $('table').children().hide();
      

      【讨论】:

      • .children() 仅深入 1 级。 find() 是递归的。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-13
      • 1970-01-01
      • 2011-05-09
      • 2019-07-30
      相关资源
      最近更新 更多