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

Detailed explanation of jQuery getting all parent elements, sibling elements and child element instances

小云云
Release: 2018-01-24 10:36:46
Original
2104 people have browsed it

This article mainly introduces jQuery's method of obtaining all parent elements, sibling elements, and child elements. This article introduces you to it in very detail and has reference value. Friends who need it can refer to it. I hope it can help everyone.

1. Get the parent element

$("#id").parent()

Get its parent 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").next (selector)

Get the next sibling element immediately next to the matched 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").prev(selector)

Get the immediately preceding sibling element of the matched element (opposite to next)

$("#id").prevAll(selector)

Get all sibling elements in front of 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

Related recommendations:

JS and jquery implementation method of obtaining parent elements, child elements, and sibling elements_javascript skills

Introduction to jQuery parent and sibling element search _jquery

How to use jquery selector to get parent elements, sibling elements, and child elements_jquery


The above is the detailed content of Detailed explanation of jQuery getting all parent elements, sibling elements and child element instances. For more information, please follow other related articles on the PHP Chinese website!

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