Select previous elements by class name
Description
The following code shows how to select the previous element for div and sets its style.
Example
<html>
<head>
<script
src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {<!-- w w w . j a va2 s . c o m-->
$("div").prev(".selected").css("background", "yellow");
});
</script>
</head>
<body>
<div class="selected">java2s.com</div>
<div>java2s.com</div>
</body>
</html>