Home > Web Front-end > JS Tutorial > body text

jQuery中children()方法用法实例_jquery

WBOY
Release: 2016-05-16 16:21:41
Original
2010 people have browsed it

本文实例讲述了jQuery中children()方法用法。分享给大家供大家参考。具体分析如下:

此方法取得一个包含匹配元素集合中每一个元素的所有子元素的元素集合。
可以通过可选的表达式来过滤所匹配的子元素。

注意:find()将查找所所有子元素,而children()只获取一级子元素。

语法结构:

复制代码 代码如下:
$(selector).children(expr)

参数列表:

参数 描述
expr 可选。用以过滤子元素的表达式

实例代码:

实例一:

复制代码 代码如下:






children()函数-脚本之家







  

我是孙子p



我是儿子p



我是兄弟p




此方法只匹配一级子元素。

实例二:

复制代码 代码如下:






children()-脚本之家

 




  

我是孙子p



我是儿子p



我是兄弟p




以上代码可以将处class属性值为children的子元素中的字体颜色设置为红色。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!