How to use the parent method of jquery
This article mainly introduces the relevant knowledge of "how to use the parent method of jquery". The editor shows you the operation process through the actual case. The operation method is simple, fast and practical. I hope this article "how to use the parent method of jquery" can help you solve the problem.
In jquery, the parent () method is used to return the immediate parent of the selected element, and the result is a collection of elements that contain the only parent of all matching elements. You can set parameters to narrow the search parent with the syntax of "$(selector) .parent (filter)".
The operating environment of this tutorial: windows10 system, jquery1.10.2 version, Dell G3 computer.
How to use the parent method of jquery
Returns the direct parent of the selected element
Parent () method:
Parent ([expr]): gets a collection of elements that contain the unique parent of all matching elements.
The syntax is:
$(selector) .parent (filter)
Filter is optional. Specifies a selector expression that narrows the search for the parent element.
Examples are as follows:
123.ancestors * {display: block;border: 2px solid lightgrey;color: lightgrey;padding: 5pxt margin: 15px;} $(document) .ready (function () {$("span"). Parent (). Css ({"color": "red", "border": "2px solid red"}); body (great-grandfather node) div (great-grandfather node) ul (grandfather node) li (direct parent node) span
Output result:
This is the end of the content about "how to use the parent method of jquery". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.