JQuery does the next iteration based on the current element
- 2020-03-30 03:02:14
- OfStack
If we have selected a set of elements through jQuery methods, how do we iterate over the selected elements in the next step?
For example, we pass
$(' li: eq (1))
The second li element in the following code is selected.
Based on this selected element, we can further iterate over the other elements
Next element
$(' li: eq (1)). The next ()
Previous element
$(' li: eq (1)). The prev ()
The parent element
$(' li: eq (1)), the parent ()
All sibling elements
$(' li: eq (1)), the parent () the children ()
All subsequent sibling elements
$(' li: eq (1)). NextAll ()
All previous sibling elements
$(' li: eq (1)). PrevAll ()
All of the above traversal methods can be cancelled using the end() method.
Of course, you can also use parameters, such as
$(' li: eq (1)), the parent () the children (' last '.)
For example, we pass
$(' li: eq (1))
The second li element in the following code is selected.
<ul>
<li><a href="#">link</a></li>
<li><a href="#">selected link</a></li>
<li><a href="#">link</a></li>
<li><a href="#">link</a></li>
</ul>
Based on this selected element, we can further iterate over the other elements
Next element
$(' li: eq (1)). The next ()
Previous element
$(' li: eq (1)). The prev ()
The parent element
$(' li: eq (1)), the parent ()
All sibling elements
$(' li: eq (1)), the parent () the children ()
All subsequent sibling elements
$(' li: eq (1)). NextAll ()
All previous sibling elements
$(' li: eq (1)). PrevAll ()
All of the above traversal methods can be cancelled using the end() method.
Of course, you can also use parameters, such as
$(' li: eq (1)), the parent () the children (' last '.)