Get the App
SLTechnology News&Howtos  ›  Development  › 

How does jquery get the first child of the parent node

Shulou Source: shulou.com Published: 2022-05-31 17:48:16 09月10日 Update

This article mainly explains "jquery how to get the first child node of the father node". 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 "how to get the first child node of the father node by jquery".

Method: 1, use children () to get all the direct child nodes under the specified parent node, will return a collection object; 2, use the ": first-child" selector to get the first node in the child node collection, the syntax is "$(parent node) .children (": first-child ")".

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

Jquery gets the first child of the parent node

In jquery, you can use the children () method and the: first-child selector to get the first child of the parent node.

Realize the idea:

The children () method gets all the direct child nodes under the specified parent node

The first-child selector gets the first node in the child node collection

Implementation example:

$(function () {$("button") .click (function () {$("ul"). Children (": first-child") .css ("color", "red") }) the first child node of the parent element ul of banana, apple, pear, orange

Thank you for your reading, the above is the content of "how jquery gets the first child node of the father node". After the study of this article, I believe you have a deeper understanding of how jquery gets the first child node of the father node, 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 stature father method learning selection content elements objects that is thoughts ideas situations tutorials articles more pears oranges versions environment Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn NVidia MariaDB Shulou Technology Xiaomi