Filter by attribute value

Description

The following code shows how to filter by attribute value.

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() {<!--from   w  ww . jav  a  2 s.  com-->
    $("div").css("background", "blue").filter(function(index) {
      return $(this).attr("id") == "fourth";
    }).css("border", "1px solid red");
  });
</script>
<style>
div {
  border: 2px white solid;
}
</style>

</head>
<body>
<body>
  <div id="first">java2s.com</div>
  <div id="second">java2s.com</div>
  <div id="third">java2s.com</div>
  <div id="fourth">java2s.com</div>
  <div id="fifth">java2s.com</div>
  <div id="sixth">java2s.com</div>
</body>
</html>

Click to view the demo





















Home »
  jQuery »
    jQuery Example »




Animation
DOM
Event
Form
List
Select
Style
Table
Utilities