As we use parent () to get the parent node
The code is as follows |
Copy Code |
$ (' #cur '). Parent (). parent (); Or $ (' #cur '). Parent (). Parent ('. pp '); Or $ (' #cur '). Parent ('. pp '); |
The main differences between closest and parents are:
The former matches the search from the current element, the latter starting from the parent element to find
The former is searched up until a matching element is found, the latter is searched up until the root element, and then the elements are placed in a temporary set and then filtered with the given selector expression.
The former returns 0 or 1 elements, which may contain 0, 1, or more elements
Capture of the jquery sibling node
The code is as follows |
Copy Code |
<ul> <li>
<ul> <li> the first </li> <li> the second </li> </ul> </li> <li>
<ul> <li> the first </li> <li> the second </li> </ul> </li></ul> |
For example, to click on the H3 of a class, the UL of its brother node to add a class called "show", the code is as follows:
The code is as follows |
Copy Code |
$ (". Title"). Click (function () {$ (this). Parent (). Find (' ul '). addclass (' Show ');}; |
is by first find H3 and UL common parent node Li then to use Find () found UL, there is another way is to use the siblings () function, the code is as follows:
The code is as follows |
Copy Code |
(". Title"). Click (function () {$ (this). Siblings (' ul '). addclass (' Show ');})
|
How the child nodes are obtained.
The code is as follows |
Copy Code |
$ ("#tbody1: First-child")
: First-child |
Match first child element
': A ' matches only one element, and this selector matches one child element for each parent element