:even Selector - Javascript jQuery Selector

Javascript examples for jQuery Selector:even

Description

The :even selector selects each element with an even index number (like: 0, 2, 4, etc.).

The index numbers start at 0.

The following code shows how to select every other (even) <tr> element:

Demo Code

ResultView the demo in separate window

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

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

<table border="1">
  <tr>
    <th>Company</th>
    <th>Country</th>
  </tr>
  <tr>
    <td>A</td>
    <td>A</td>
  </tr>
  <tr>
    <td>C</td>
    <td>D</td>
  </tr>
  <tr>
    <td>E</td>
    <td>G</td>
  </tr>
  <tr>
    <td>E</td>
    <td>A</td>
  </tr>
  <tr>
    <td>I</td>
    <td>U</td>
  </tr>
</table>

</body>
</html>

Related Tutorials