ドキュメント

Selectors/odd

From jQuery JavaScript Library

Jump to: navigation, search

« Back to Selectors

:odd

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

Finds odd table rows, matching the second, fourth and so on (index 1, 3, 5 etc.).

$("tr:odd").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:odd").css("background-color", "#bbbbff");
  });
  </script>
  <style>
  table {
    background:#f3f7f5;
  }
  </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