Blogger Trick : Applying Zebra Striping in Comments after each post.

An another idea to improve readability and visual appearance of comments section could be to apply Zebra Striping. In simple words Applying alternate colors.

To add Zebra Striping add the below Javascript : Include jQuery library. Add below line just before </head> section.
<script src='http://code.jquery.com/jquery-latest.min.js' type='text/javascript'></script>

Add below code to just before </body> section.

<script type="text/javascript">
$(document).ready(function() {
$("#comments-block dt").each(function(i){
      var divId='zpk' + i.toString();
      $(this).before("<div id='" + divId + "'></div>");
      $(this).next().next().prependTo("#" + divId);
      $(this).next().prependTo("#"  + divId);
      $(this).prependTo("#"  + divId);
      $("#" + divId).css("padding","10px");
       if(i%2==0){
        $("#" + divId).css("background-color","#cdd1f3");
       }else{
       $("#" + divId).css("background-color","#ffffff");
       }
 });
});
</script>

Related Posts:
Blogger Trick : Displaying post titles as summary on index pages
Blogger Trick : Adding numbering to comments after each post using jQuery
Blogger Trick : Make sidebar column height equal to the main content using jQuery

3 Comments:

Anonymous said...

Please correct the error below, and submit your template again.
Your template could not be parsed as it is not well-formed. Please make sure all XML elements are closed properly.
XML error message: Element type "scriptsrc" must be followed by either attribute specifications, ">" or "/>".
how I correct it? Thanks for sharing brother! :)

Anonymous said...

<scriptsrc=... no space in that code, hehe

problem fixed, Thanks

AK said...

Thanks for mentioning issue .. I have corrected it. You can also take the exact source code from doing a view source from demo page.

Post a Comment