jQuery traversal prev() method
jQuery is a collection object. If you want to quickly find the element set of the previous sibling elements immediately adjacent to each element in the specified element set, you can use the prev() method
to understand the node search relationship:
The following is the blue li element with class="item-2", and the red node is its prev sibling node
- 1
3">3
prev() no parameters Gets a set containing matching elements immediately adjacent to each element The set of elements of the previous sibling elements Note: jQuery is a collection object, so prev is the previous sibling element that matches each element in the collection
Adding a selector in prev() is to further filter the previous set of elements, such as: eq(1), first, last, :contains("3") , has('p'), add a selector that meets your needs to filter. This is the same as next(), but their functions are differentprev方法()
- 1
- 2
- 3
- 1
- 2
- 3
- 1
- 2
- 3