jQuery find() 方法

jQuery 教程 · 2019-03-28 06:39:42

实例

返回 <ul> 后代中所有的 <span> 元素:

$(document).ready(function(){
$("ul").find("span").css({"color":"red","border":"2px solid red"});
});

结果:

body (great-grandparent)
div (grandparent)
    ul (parent)
  • li (child) span (grandchild)

定义和用法

find() 方法返回被选元素的后代元素。

后代是子、孙、曾孙,依此类推。

DOM 树:该方法沿着 DOM 元素的后代向下遍历,直至最后一个后代的所有路径(<html>)。如只需向下遍历 DOM 树中的单一层级(返回直接子元素),请使用 children() 方法。

注意:filter 参数在 find() 方法中是必需的,这与其他树遍历方法不同。

提示:如需返回所有的后代元素,请使用 "*" 选择器。

语法

$(selector).find(filter)

参数 描述
filter 必需。过滤搜索后代条件的选择器表达式、元素或 jQuery 对象。

注意:如需返回多个后代,请使用逗号分隔每个表达式。

点击查看所有 jQuery 教程 文章: https://codercto.com/courses/l/35.html

查看所有标签

The Art of Computer Programming, Volume 2

The Art of Computer Programming, Volume 2

Knuth, Donald E. / Addison-Wesley Professional / 1997-11-04 / USD 79.99

Finally, after a wait of more than thirty-five years, the first part of Volume 4 is at last ready for publication. Check out the boxed set that brings together Volumes 1 - 4A in one elegant case, and ......一起来看看 《The Art of Computer Programming, Volume 2》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具