Get the App
SLTechnology News&Howtos  ›  Development  › 

What is children in jQuery

Shulou Source: shulou.com Published: 2022-05-31 17:36:21 10月05日 Update

This article mainly explains "what is children in jQuery". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is children in jQuery".

In jQuery, children means "children" and is a filter used to filter the children of the current jQ object to get eligible children, that is, to find all child elements; the syntax is "object .children (filter)", and the parameter "filter" is used to set conditions to narrow the search for child elements.

The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.

In jQuery, children means "children".

Children is a filter, as the name implies, to filter children, to filter the children of the current jQ object, to get eligible children, that is, to find child elements.

The children () method returns all direct child elements of the selected element. This method only traverses a single level down the DOM tree.

Syntax:

$(selector) .children (filter)

Parameter "filter": used to set conditions that specify selector expressions that narrow the scope of the search child elements.

Example 1: all direct child elements returned

Display: block; border: 2px solid lightgrey; color: lightgrey; padding: 5px; margin: 15px } $(document) .ready (function () {$("ul"). Children (). Css ({"color": "red") "border": "2px solid red"}) }) Body (great ancestor node) div (ancestor node) ul (direct parent node) li (child node) span (grandnode) Li (child node) span (grandnode)

Example 2: narrow the search

All elements with the class name "1" in the immediate child elements returned using the filter parameter

Display: block; border: 2px solid lightgrey; color: lightgrey; padding: 5px; margin: 15px } $(document) .ready (function () {$("ul"). Children ("li.1"). Css ({"color": "red") "border": "2px solid red"}) }) Body (great ancestor node) div (ancestor node) ul (direct parent node) li (child node) span (grandnode) Li (child node) span (grandnode)

Thank you for your reading, the above is the content of "what is children in jQuery". After the study of this article, I believe you have a deeper understanding of what the children in jQuery is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Nodes elements children conditions ancestors parameters objects scope learning content that is meaning methods examples grammar soxons filters as the name implies hierarchy ideas Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Redmi MariaDB Shulou Information Shulou Technology