Using jQuery and not CSS, is it possible to alternate row colors between records? If so can anyone provide a short code script on how to accomplish this?
相关问题
- How to fix IE ClearType + jQuery opacity problem i
- jQuery add and remove delay
- Include empty value fields in jQuery .serialize()
- Disable Browser onUnload on certain links?
- how to get selected text from iframe with javascri
You can select
tr
elements from a table and css accepts a function as a parameter, which will return a value based on some criteria you decide. In this case, you can test the index for evenness.JSFiddle: http://jsfiddle.net/n3Zny/
For anyone wanting to skip over hidden rows (or another attribute, say
class="struck"
):Do you just not want to use CSS for cross-browser (i.e., IE) support? If so, you could keep the styling in the CSS and just use jQuery to set the class.
For example:
jQuery uses the Sizzle Seletor Engine, which is cool because it uses the same syntax as CSS. So you use the same selector as CSS but then use the jQuery
.css()
function to alter the elemen't CSS:This code example selects the table you want to alter, then selects all the even child elements (
tr
's) and changes their background color, it then uses.end()
to return to the previous selection of the entire table and selects the odd rows to alter their CSS.I used following code to change color of alternate row. I have taken reference from http://www.tutsway.com/set-alternate-row-colors-in-jQuery.php
Try this: