The advent of jquery has provided a lot of convenience to the vast number of developers. From the need to own a knock code, to the direct call method, undoubtedly greatly improve the efficiency of website development. Some of the methods in jquery are very practical. The following is a description of the jquery selector: Gets the parent element, sibling element, child element method.
First, get the parent element
1.parent ()
Gets the parent element of the specified element, note: is the parent element closest to the specified element.
2.parents ()
Gets all the parent elements of the specified element, note: All parent elements, including body,html
Second, get the sibling element
1.next ()
Gets the next sibling element of the specified element (note: Is the next sibling element)
2.nextAll ()
Gets all sibling elements following the specified element (note: all sibling elements)
3.andSelf ()
Gets the specified element, which is itself. This method can be used in the use of it? In fact, it is also very common.
For example: Gets all the sibling elements behind the specified element, followed by the specified element
This time you can write $ ('. Div1 '). Nextall (). Andself ()
4.prev ()
Gets the previous sibling element of the specified element. (Contrary to next () method)
5.prevAll ()
Gets all the sibling elements in front of the specified element. (Contrary to the Nextall () method)
Third, get child elements
1.chidren ()
Gets all child elements under the specified element, note: Chidren () traverses only a single level.
2.find ()
. Find () is similar to the. Children () method, but find () must have parameters, that is, it must pass a parameter (selector) to find (). The Find () method is to get all child elements under the specified element (regardless of how many layers are nested in the specified element)
This article originates from: http://yunkus.com/article/jquery/37.html
jquery selector: Gets the parent element, sibling element, child element