Home >Web Front-end >JS Tutorial >How to get parent elements, sibling elements, and child elements using jquery selector_jquery
1. Get the parent element
1. parent([expr]):
Get all parent elements of the specified element
" tag, the class name 'p_next_all' is also added~~
3. andSelf():
Gets all the sibling elements behind the specified element, and then adds the specified element
I think this function is the most interesting one. What does it mean? ? The literal translation is "and I", "and myself", yes, there is still myself.
Hello
" tag. This sentence means to select all sibling tags after the p tag, as well as itself. . .
The following two will not give specific examples. They are actually the opposite of next() and nextAll()
4. prev(): Get the previous sibling of the specified element Element (the previous one).
5. prevAll(): Get all sibling elements in front of the specified element.
3. Get sub-elements
1. Search sub-element method 1: >
For example: var aNods = $("ul > a"); Find ul All a tags under
2. Method 2 to find child elements: children()
3. Method 3 to find child elements: find()
Here we briefly introduce the following Similarities and differences between children() and find():
1> The children and find methods are both used to obtain the child elements of element. Both will not return text node, just like most jQuery methods. Same.
2> The children method only obtains the child elements below the element, namely: immediate children.
3> The find method obtains all subordinate elements, that is: descendants of these elements in the DOM tree
4> The parameter selector of the children method is optional (optionally) and is used to filter child elements,
But the parameter selector method of the find method is required.
5> The find method can actually be implemented by using jQuery(selector, context). That is, $('li.item-ii').find('li') is equivalent to $('li', 'li.item-ii').
Example: