jQuery Tutorial Tutorials - jQuery :odd selector

jQuery :odd selector

The :odd selector get the odd element from the matched set.The index is based on 0. So the matched elements would have index like 1,3,5,7 etc.

jQuery :odd selector syntax

$(':odd')

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:odd').css('background-color','grey');
</script>

Try now

Date:2019-08-18 02:15:14 From:www.Lautturi.com author:Lautturi