jQuery Selector :even

Introduction

The :even selector selects elements by even index number.

The index numbers start at 0.

$(":even")

Select every other (even) <tr> element:

View in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("tr:even").css("background-color", "yellow");
});//from   w w w.  j av a 2  s .  c  o  m
</script>
</head>
<body>

<h1>Welcome to My Web Page</h1>

<table border="1">
  <tr>
    <th>Company</th>
    <th>Country</th>
  </tr>
  <tr>
    <td>CSS</td>
    <td>Germany</td>
  </tr>
  <tr>
    <td>A</td>
    <td>Sweden</td>
  </tr>
  <tr>
    <td>Javascript</td>
    <td>Mexico</td>
  </tr>
  <tr>
    <td>C++</td>
    <td>XYZ</td>
  </tr>
  <tr>
    <td>Ruby</td>
    <td>UK</td>
  </tr>
</table>

</body>
</html>



PreviousNext

Related