jquery 后代元素

In this post, we are going to discuss about an important jQuery traversing method to find all the descendents of an element. jQuery API provides find() method to carry out this task.

在本文中,我们将讨论一种重要的jQuery遍历方法,以查找元素的所有后代。 jQuery API提供了find()方法来执行此任务。

jQuery find()方法 (jQuery find() method)

The jQuery find() method returns all the descendant elements like child, grandchild and so on. This method is used if you want to search all the elements deeper in the DOM tree. This method traverses downwards and finds all its descendants of the selected element. This method takes a mandatory filtering parameter to narrow down the search.

jQuery find()方法返回所有后代元素,例如child,孙子等等。 如果要搜索DOM树中更深的所有元素,则使用此方法。 此方法向下遍历并找到所选元素的所有后代。 此方法采用强制性的过滤参数来缩小搜索范围。

Here is the general syntax for using find() method:

这是使用find()方法的一般语法:

  • selector.find(filter)选择器。查找(过滤器)

filter is the mandatory parameter passed to the find() method. filter could be any string selector expression, an element or a jQuery object.

filter是传递给find()方法的必需参数。 filter可以是任何字符串选择器表达式,元素或jQuery对象。

jQuery find()示例 (jQuery find() example)

Following example demonstrates the jQuery find() method usage.

以下示例演示了jQuery find()方法的用法。

<!doctype html>
<html>
<head>
<title>jQuery Traversing find</title>
<style>.highlight{background: yellow;}div{display: block;border: 3px solid black;color: black;padding: 5px;margin: 25px;width:250px;}span{display: block;border: 3px solid green;color: black;padding: 5px;margin: 25px;width:200px;}
</style>
<script src="https://code.jquery.com/jquery-2.1.1.js"></script>
</head>
<body>
<h2>jQuery find() demo</h2>
<div>div
<p> p - I am div's child</p>
<span>span <p>p - I am span's Child and div's Grand Child</p></span>
</div>
<script>
$( "div" ).find( "p" ).addClass("highlight");
</script>
</body>
</html>

In this example, you can see two p elements, one element is div element’s child and the other one is it’s grandchild. The find() method finds all the p element of the selected div element and changes the color to red. Below image shows the output produced by above HTML page.

在此示例中,您可以看到两个p元素,一个元素是div元素的子元素,另一个元素是其孙子元素。 find()方法查找所选div元素的所有p元素,并将颜色更改为红色。 下图显示了以上HTML页面产生的输出。

You can use selector.find("*") to find all the descendants of the HTML document.

您可以使用selector.find("*")查找HTML文档的所有后代。

That’s all for now and you can find more traversing methods in the coming posts.

到此为止,您可以在以后的文章中找到更多的遍历方法。

翻译自: https://www.journaldev.com/5342/find-descendants-element-jquery

jquery 后代元素

jquery 后代元素_在jQuery中查找元素的所有后代相关推荐

  1. JAVA中修改顺序表中的元素_java – 在列表中查找元素并使用stream()更改它

    如果您的目标是只找到一个元素,那么您可以这样做 MyItem item = l.stream() .filter(x -> x.getValue() > 10) .findAny() // ...

  2. scala 获取数组中元素_从Scala中的元素列表中获取随机元素

    scala 获取数组中元素 We can access a random element from a list in Scala using the random variable. To use ...

  3. java交换数组元素_交换数组中的元素(Java)

    是否有任何Java中的数组预定义的方法与哪个可以 直接交换两个元素? 默认Java API没有任何交换数组元素的函数.但是,您可以使用Collections.swap(list, index1, in ...

  4. 算法----- 在排序数组中查找元素的第一个和最后一个位置

    题目: 在排序数组中查找元素的第一个和最后一个位置给定一个按照升序排列的整数数组 nums,和一个目标值 target.找出给定目标值在数组中的开始位置和结束位置.你的算法时间复杂度必须是 O(log ...

  5. python 在排序数组中查找元素的第一个和最后一个位置

    在排序数组中查找元素的第一个和最后一个位置 给定一个按照升序排列的整数数组 nums,和一个目标值 target.找出给定目标值在数组中的开始位置和结束位置.如果数组中不存在目标值 target,返回 ...

  6. LeetCode (二分小专题)33搜索旋转排序数组34在排序数组中查找元素的第一个和最后一个位置35搜索插入位置

    前言 国庆前最后一次打卡,国庆后继续开启,公众号bigsai回复进群欢迎加入打卡,如有帮助记得点赞收藏. 近期打卡记录: LeetCode 32最长有效括号(困难) (本周) LeetCode 30串 ...

  7. 6、leetcode34 在排序数组中查找元素的第一个位置和最后一个位置**

    leetcode34 在排序数组中查找元素的第一个位置和最后一个位置 给定一个按照升序排列的整数数组 nums,和一个目标值 target.找出给定目标值在数组中的开始位置和结束位置. 如果数组中不存 ...

  8. leetcode(34)在排序数组中查找元素的第一个和最后一个位置

    在排序数组中查找元素的第一个和最后一个位置 class Solution {public int[] searchRange(int[] nums, int target) {int len = nu ...

  9. 34. 在排序数组中查找元素的第一个和最后一个位置 golang

    34. 在排序数组中查找元素的第一个和最后一个位置 https://leetcode-cn.com/problems/find-first-and-last-position-of-element-i ...

  10. 去掉数组最后一个元素_leetcode 34. 在排序数组中查找元素的第一个和最后一个位置每天刷一道leetcode算法系列!...

    作者:reed,一个热爱技术的斜杠青年,程序员面试联合创始人 前文回顾: leetcode1. 两数之和--每天刷一道leetcode系列! leetcode2. 两数相加--每天刷一道leetcod ...

最新文章

  1. java 时间l_java中获取系统时间并格式化输出
  2. 纯js实现人脸识别眨眨眼张张嘴案例——alive_face.js
  3. java 线程中创建线程_如何在Java 8中创建线程安全的ConcurrentHashSet?
  4. java 复制对象_Java程序员必备:序列化全方位解析
  5. java bitmap取出数据库_bitmap一般如何取出其所表示的数据(以java为例)
  6. iis5.1安装方法(适用于XP)以及运行调试asp程序,创建虚拟目录【整理】
  7. 关于 IdentityServer4 中的 Jwt Token 与 Reference Token
  8. 文件IO open 与 标准 IO fopen 的对应
  9. AC日记——独木桥 洛谷 p1007
  10. Python 3.5安装JPype
  11. Beyond Compare 4 智能比较工具、Everything 文件/夹搜索工具,WinRAR,7-Zip 解压缩工具、diagrams 流程图工具
  12. GeoNet: Deep Geodesic Networks for Point Cloud Analysis
  13. 创业三十年后说了五遍 hard:乔布斯在日本被遗忘的声音
  14. android手机——刷机(卡刷、线刷)
  15. 全志XR829 WIFI和BT模块在T7 Android8.1上调试
  16. html折叠新闻网页版本号,数字报纸HTML版本
  17. Workspaces can only be enabled in private projects.
  18. PyQt5:QMessageBox显示后程序崩溃退出问题
  19. 第二章 系统集成及服务管理知识点1
  20. 南京航空航天大学计算机学院保研,南京航空航天大学计算机学院2018招收推免生办法...

热门文章

  1. .NET 环境中使用RabbitMQ(转)
  2. ORACLE常用系统查询
  3. JAVA中的hasNextInt()方法多次调用只有一个结果的原因
  4. 桌面恶心的无法删除的图标之 淘宝购物 删除办法
  5. 系统也需和谐共存——Win7与XP安装同一盘符方法解析
  6. Csdn Blog 开发团队致广大网友的一封信
  7. [转载] python中@property和property函数使用
  8. [转载] python创建集合set()_python 之集合{}(Set)
  9. 用MySQLdb操作数据库流程示例:
  10. jq中each的中断