While working with asp.net mvc project, we will get scenario to display the alternate color of tabular grid. We can do this task using Jquery selector in very easy way like this
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="../Scripts/jquery.min.js"></script> <script> $(function () { $("tr:odd").css("background-color", "yellow"); }); </script> </head> <body> <fieldset> <legend><b>Alternate table row color using Jquery selector</b></legend> <table border="1"> <tr> <th>EmpName</th> <th>City</th> <th>Contact Num</th> </tr> <tr> <td>Ram</td> <td>Bangalore</td> <td>1234567890</td> </tr> <tr> <td>Hari</td> <td>Bangalore</td> <td>1234567890</td> </tr> <tr> <td>Mohan</td> <td>Bangalore</td> <td>1234567890</td> </tr> <tr> <td>Rohan</td> <td>Bangalore</td> <td>1234567890</td> </tr> </table> </fieldset> </body> </html>
Note: in above example we have used $(“tr:odd”) as Selector