w3resource

jQuery: Create a Zebra Stripes table effect

jQuery Practical exercise Part - I : Exercise-7

Create a Zebra Stripes table effect.

Sample solution :

HTML Code :

<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
  <meta charset="utf-8">
  <title>Create a Zebra Stripes table effect</title>
</head>
<body>
<div class="table_style">
<table>
	<tr>
		<th>Student Name</th>
		<th>Marks in Science</th>
	</tr>
	<tr>
		<td>Janet</td>
		<td>85.00</td>
	</tr>
	<tr>
		<td>David</td>
		<td>92.00</td>
	</tr>
	<tr>
		<td>Arthur</td>
		<td>79.00</td>
	</tr>
	<tr>
		<td>Bill</td>
		<td>82.00</td>
	</tr>
</table>
</div>
</body>
</html>

CSS Code:

.table_style {
	width: 500px;
	margin: 0px auto;
	}
	table{
	width: 100%;
	border-collapse: collapse;
	}
	table tr td{
	width: 50%;
	border: 1px solid #ff751a;
	padding: 5px;
	}
	table tr th{
	border: 1px solid #79ff4d;
	padding: 5px;
	}
	.zebra{
	background-color:  #ff0066;
	}
	</style>

JavaScript Code :

$(document).ready(function(){
	$("tr:odd").addClass("zebra");
});

See the Pen jquery-practical-exercise-7 by w3resource (@w3resource) on CodePen.


Contribute your code and comments through Disqus.

Previous: Blink text using jQuery.
Next: Print a page using jQuery.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/jquery-exercises/part1/jquery-practical-exercise-7.php