Probably a dumb question but I'm new to MVC and jQuery. I want to alternate the row colors of my tables and I've decided that I'm going to use jQuery to do it. I know that I could write an extension method (http://haacked.com/archive/2008/08/07/aspnetmvc_cycle.aspx), etc but after reading SH's comment on the article at http://haacked.com/archive/2008/05/03/code-based-repeater-for-asp.net-mvc.aspx I've picked jQuery as the solution I want to implement.
I want to implement the method described at http://www.packtpub.com/article/jquery-table-manipulation-part2 but I haven't figured out where to put the initial jQuery call (eg: $(document).ready(function() {...});
Like I said, I'm new to jQuery...
You can accomplish this by setting a class on all the even rows of a table.
<html>
<head>
<title>Example Title</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('tr:even').addClass('alt-row-class');
});
</script>
</head>
<body>...</body>
</html>
Then apply style to that class using standard css:
.alt-row-class { background-color: green; }
A commenter correctly points out that you might wish to play around with the selector (tr:even
) to get the results you want relative to tbody
, thead
and tfoot
elements.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With