tr even Selects all even rows of table – jQuery


$( “tr:even” ) – selector is used to select the even rows of the table.


tr even Selects all even rows of table with jQuery Syntax

tr even Selects all even rows of table – jQuery Example

<!DOCTYPE html>
<html>
<head>
<title>tr even Selects all even rows of table - jQuery Example</title>
 <script type="text/javascript" src="http://code.jquery.com/jquery-2.1.4.min.js">
 </script>
<script type="text/javascript">
         $(document).ready(function(){
         $("#demo").click(function(){
         $("#myTable > tbody > tr:even").css("background","yellow");

         
          });
          });
</script> 
  
</head>	
<body>
<a href="javascript:void(0)" id="demo"> 
Click Me To Select Even Rows
</a><br><br>
<table id='myTable'>

<tbody>
 <tr><td>Jhohn</td><td>jhone@gmail.com</td><td>USA</td></tr>
 <tr><td>Kelly</td><td>kelly@gmail.com</td><td>USA</td></tr>
<tr><td>Kamana</td><td>kamna@gmail.com</td><td>India</td></tr>
<tr><td>Anay</td><td>anay@gmail.com</td><td>Canada</td></tr>
<tr><td>AnaMy</td><td>amy@gmail.com</td><td>Canada</td></tr>
<tr><td>Rummy</td><td>asd@gmail.com</td><td>Canada</td></tr>
<tr><td>Jelly</td><td>y@gmail.com</td><td>Canada</td></tr>
 </tbody>
</table>

</body>
</html>             

Try it »

Note : Row Index starts from 0,1,2….


Advertisements

Add Comment

📖 Read More