.append()
.prepend()
.before()
.after()
.replaceWith()
.wrap()
.wrapInner()
.offset()
.addClass()
.removeClass()
.toggleClass()
.css( propertyName, function(index, value))
<ul> <li>item 1</li> <li>item 2</li> <li>item 3</li> <li>item 4</li> <li>item 5</li> <li>item 6</li> <li>item 7</li></ul>
$(document).ready(function(){ $("li").css("background-color", function(i){ return (i % 2 === 0) ? "#cccccc": "#FFFFFF"; });});
We select all the LIs and call the .css() setter method. We give it the property name we want to update, background-image and we pass a function that will return the value we want to set.
LI
.css()
background-image
The function tests if the index that we passed in i is MOD 2 (simply is it even or odd), if even set the color to #cccccc else set it to #FFFFFF.
i
#cccccc
#FFFFFF
Note: Obviously, this isn't the best way to do zebra stripping with jQuery but I like to explore different ways to do the same thing to learn the techniques.
Remember Me
with Ralph Whitbeck & Elijah Manor
You can subscribe to the show in iTunes or via the raw RSS feed