now musing at www.aliaspooryorik.com!

February 17, 2008

Alternate rows with jQuery (Tiger / Zebra Stripes)

Filed under: ColdFusion, jQuery — aliaspooryorik @ 9:01 pm

It’s always been a pain to add alternate styles to table rows, lists etc. With jQuery you can do this easily, you can even make it apply globally to you site.

Example:

$("table.tiger-stripe tr:even").addClass("oddrow");

It is worth noting that jQuery (and Javascript) starts counting from zero. So, the above example will apply the oddrow class to the 1st, 3rd, 5th, etc rows.

If you want to do it all with server side code to be ultra-accessible then in ColdFusion you can do something like this:

<table>
<cfloop query="myQuery">
	<tr class="<cfif currentrow MOD 2>evenrow<cfelse>oddrow</cfif>">
		<td>...</td>
	</tr>
</cfloop>
</table>

No Comments Yet »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.