ドキュメント

Selectors/even

From jQuery JavaScript Library

Jump to: navigation, search

« Back to Selectors

:even

Matches even elements, zero-indexed. See also odd
Examples:

Finds even table rows, matching the first, third and so on (index 0, 2, 4 etc.).

$("tr:even").css("background-color", "#bbbbff");

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
                    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
  
  <script>
  $(document).ready(function(){
    $("tr:even").css("background-color", "#bbbbff");
  });
  </script>
  <style>
  table {
    background:#eeeeee;
  }
  </style>
</head>
<body>
  <table border="1">
    <tr><td>Row with Index #0</td></tr>
    <tr><td>Row with Index #1</td></tr>
    <tr><td>Row with Index #2</td></tr>
    <tr><td>Row with Index #3</td></tr>
  </table>
</body>
</html>

NameType