JQuery Selector even

From CoderLearner
Jump to: navigation, search

Description

Select all even elements.

Syntax

$(':even')

Example 1

<!DOCTYPE html>
<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>Select</title>
      <script 
         type="text/javascript" 
         src="/lib/jquery-1.7.2.min.js">				 
      </script>

      <script>
         $().ready(function() {
            $('table tr').filter(':even').css('background-color','green');
         });
      </script>
   </head>
   <body> 
      <table border="1">
         <tr>
            <th>No</th>
            <th>Name</th>
            <th>Age</th>
         </tr>
         <tr>
            <td>1</td>
            <td>Nanak</td>
            <td></td>
         </tr>
         <tr>
            <td>2</td>
            <td>Lilo</td>
            <td></td>
         </tr>
         <tr>
            <td>3</td>
            <td>Bob</td>
            <td>14</td>
         </tr>

      </table>
   </body>
</html>

Try It