Home >Web Front-end >JS Tutorial >jQuery selector gets all parent elements and below elements at once
This time I will bring you jQueryThe selector obtains all parent elements and the following elements at one time, and the jQuery selector obtains all the parent elements and the following elements at one timeNotesWhat are they? Here are actual cases. Let’s take a look.
1. Get the parent element
$("#id").parent()
Get its parent Level element
$("#id").parents()
Get all its ancestor elements
$("# id").closest()
Get its nearest ancestor element and trace back in sequence
------------------- -------------------------------------------------- -----------
2. Get sibling elements
$("#id").<a href="http://www.php.cn/wiki/1071.html" target="_blank">next </a>(selector)
Get the next sibling element immediately next to the matching element. If a selector is provided, retrieves the next sibling element that matches the selector.
$("#id").nextAll(selector)
Get all sibling elements after the matching element. Filtering by the selector is optional.
$("#id").<a href="http://www.php.cn/wiki/1074.html" target="_blank">prev</a>(selector)
Get the immediately preceding sibling element of the matched element (opposite to next)
$("#id").prevAll(selector)
Get all sibling elements before the current matching element (opposite to nextAll)
-------------------------------------------------- ----------------------------------
3. Get child elements
$("#id").children(selector)
Returns the child elements of the matching element. Add optional parameters to filter through the selector.
$("#id").find(selector)
Get the descendants of the current element
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to the php Chinese website Other related articles!
Recommended reading:
Request ajax in jquery and response ajax in servlet
Implement jquery on the startup page Load data immediately
Realize the linkage effect between the input box and the drop-down box
How to achieve dynamic acquisition of Jquery drop-down box data
The above is the detailed content of jQuery selector gets all parent elements and below elements at once. For more information, please follow other related articles on the PHP Chinese website!