Alternating Element Highlighting With jQuery
Posted over 3 years ago on September 26, 2008
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!!
Comments
Jones writes...
Nice post...
October 20, 2008
Jason writes...
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)
October 25, 2008
New Comment