Reading tabular data is usually made a little easier by distinguishing alternating rows by a slightly different color. Normally, to accomplish this I would just assign a different CSS style using a server control such as a GridView or Repeater. While working today, I found a challenge in applying the alternating row effect because I was outputting a static HTML table with some dynamic rows thrown in the middle using a Repeater. So depending on how many dynamic rows were rendered, sometimes I would get two rows by each other with the same color.
So anyway, the solution was to implement the alternating row coloring on the client using jQuery. Here is the very simple code:
You can even substitute the <tr> tag to any html container (div/span/etc.).
jQuery rocks!!
2 comments:
Nice post...
For those able to practice a little progressive enhancement, the latest builds of Firefox, Opera and Webkit (Safari/Chrome) all pass the CSS 3 selectors test! Which means one can scap JavaScript for your presentation layer and use pure CSS! :nth-child(even) :nth-child(odd)
Post a Comment