The following snippet describes how you can add ‘Zebra Stripes’ to your tables with JavaScript and jQuery.

The colours could be applied with CSS classes in stead, which would also work in browsers with JavaScript disabled, but the interesting part here is the hover effect, which is not possible without JavaScript :)

Html:

Linie1
Linie2
Linie3
Linie4
Linie5

Add the following JavaScript code, together with the jQuery class:

$(document).ready(function() {
    $(".zebrastripe tr:even").css("background-color","gray").hover(
      function() {
        $(this).css("background-color","yellow");
      }, function() {
        $(this).css("background-color","gray");
      });
    $(".zebrastripe tr:odd").css("background-color","blue").hover(
      function() {
        $(this).css("background-color","yellow");
      }, function() {
        $(this).css("background-color","blue");
      });
  });
Share and Enjoy:
  • Print this article!
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks

Tags:

Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>