how select just before element in jquery 1

how select just before element in jquery

  • list item 1
  • list item 2
  • list item 3
  • list item 4
  • list item 5
$( "li.third-item" ).prev().css( "background-color", "red" );

Here is what the above code is Doing:
1. Selects the element with class “third-item”
2. Finds the element’s previous sibling
3. Changes the background color of the previous sibling

Similar Posts