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

Example of usage of children() method in jQuery_jquery

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

The example in this article describes the usage of the children() method in jQuery. Share it with everyone for your reference. The specific analysis is as follows:

This method obtains an element set containing all child elements of each element in the matching element set.
Matched child elements can be filtered through optional expressions.

Note: find() will find all child elements, while children() only gets first-level child elements.

Grammar structure:

Copy code The code is as follows:
$(selector).children(expr)

Parameter list:

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

Example code:

Example 1:

Copy code The code is as follows:






children() function-Script Home







I am grandson p



I am my son p



I am a brotherp




This method only matches first-level child elements.

Example 2:

Copy code The code is as follows:






children()-Script Home






I am grandson p



I am my sonp



I am a brotherp




The above code can set the font color in the child element whose class attribute value is children to red.

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!