How to use jQuery .prev() to the the preceding sibling of HTML element in the set of matched elements

1 Answer

0 votes
<!doctype html>
<html>
<head>
  <script src="js/jquery/1.11.3/jquery.min.js"></script>
</head>
<body>

<ul>
  <li>list item 1</li>
  <li>list item 2</li>
  <li id="id-item-3">list item 3</li>
  <li>list item 4</li>
</ul>
<script>
$( "#id-item-3" ).prev().css( "background-color", "purple" );
</script>
</body>
</html>

 



answered Aug 22, 2016 by avibootz
...