In this post, you will learn how to create alternate row colors in an HTML table with help of jQuery, Since the table has tr which are representing rows, so we need to change the background-color CSS property of tr in the table. We can also do the same using the CSS as well.
Jquery is a very power full library for web development, we just use add CSS class method $(“tr:even”).css of jquery to alternate table row colors. We require jquery lib for alternate row color of table.
Step 1: Include JQuery library
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
Step 2: Create a sample table in the page.
<table> <tbody> <tr> <th>Month</th> <th>Savings</th> </tr> <tr> <td>Feb</td> <td>$100</td> </tr> <tr> <td>March</td> <td>$100</td> </tr> <tr> <td>April</td> <td>$100</td> </tr> <tr> <td>May</td> <td>$100</td> </tr> </tbody> </table>
Step 3: Include below code for alternate color for div as well as a row of a table.
<script> $(document).ready(function() { //for div $("div:odd").css("background-color", "#F4F4F8"); $("div:even").css("background-color", "#EFF1F1"); //for table row $("tr:even").css("background-color", "#F4F4F8"); $("tr:odd").css("background-color", "#EFF1F1"); }); </script>
Please feel free to send queries to me using below comment section.
This tutorial helps integrate a PHP SDK with Laravel. We'll install aws-php-sdk into laravel application and access all aws services… Read More
in this quick PHP tutorial, We'll discuss php_eol with examples. PHP_EOL is a predefined constant in PHP and represents an… Read More
This Laravel tutorial helps to understand table Relationships using Elequonte ORM. We'll explore laravel table Relationships usage and best practices… Read More
We'll explore different join methods of Laravel eloquent with examples. The join helps to fetch the data from multiple database… Read More
in this Laravel tutorial, We'll explore valet, which is a development environment for macOS minimalists. It's a lightweight Laravel development… Read More
I'll go through how to use soft delete in Laravel 10 in this post. The soft deletes are a method… Read More