If we have selected a group of elements through the jQuery method, how to proceed to the next step of traversal based on these selected elements?
For example, we selected the second li element in the following code by
$('li:eq(1)')
.
Based on this selected element, we can further traverse other elements
Next element
$('li: eq(1)').next()
Previous element
$('li:eq(1)').prev()
Parent element
$('li:eq(1)').parent()
All sibling elements
$('li:eq(1)').parent(). children()
All subsequent sibling elements
$('li:eq(1)').nextAll()
All preceding sibling elements
$('li:eq(1)').prevAll()
All the above traversal methods can use the end() method to cancel the operation.
Of course, you can also use parameters, such as
$('li:eq(1)').parent().children(':last')