The element is selected using the jQuery method. How can I next traverse the selected elements? The following is a good example. If we have selected a group of elements through the jQuery method, how can we next traverse these selected elements?
For example
$ ('Li: eq (1 )')
The second li element in the following code is selected.
The Code is as follows:
- Link
- Selected link
- Link
- Link
Based on the 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 previous brothers
$ ('Li: eq (1) '). prevAll ()
You can use the end () method to cancel all the preceding traversal methods.
Of course, you can also use parameters, such
$ ('Li: eq (1) '). parent (). children (': la ')