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


prev() method selection Accept selector expressions of the same type consistently

Similarly because jQuery is a collection object, it may be necessary to filter the collection object to find the target element, so it is allowed to pass a selector expression


       

prev方法()

  • 1
  • 2
  • 3
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

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 different

Continuing Learning
||

prev方法()

  • 1
  • 2
  • 3
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3
submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!