jQuery Tutorial Tutorials - jQuery :even selector

jQuery :even selector

The :even selector get the even element from the matched set.The index is based on 0. So the matched elements would have index like 0,2,4,6 etc.

jQuery :even selector syntax

$(':even')

In below example,We will implement a striped table using jQuery.

<table>
<thead>
    <tr><th>Col Header</th><th>Col Header</th></tr>
</thead>
<tbody>
    <tr><td>Row1 Col1</td><td>Row1 Col2</td></tr>
    <tr><td>Row2 Col1</td><td>Row2 Col2</td></tr>
    <tr><td>Row3 Col1</td><td>Row3 Col2</td></tr>
    <tr><td>Row4 Col1</td><td>Row4 Col2</td></tr>
    <tr><td>Row5 Col1</td><td>Row5 Col2</td></tr>
</tbody>    
</table>

<script>
    $('tr:even').css('background-color','grey');
</script>

Try now

Date:2019-08-18 01:28:34 From:www.Lautturi.com author:Lautturi