Created
October 28, 2013 15:48
-
-
Save vdchristelle/7199273 to your computer and use it in GitHub Desktop.
Add striping (odd even classes) in jQuery - stripe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Add striping | |
* | |
*/ | |
function stripe(el){ | |
var count = 0; | |
$(el).each(function(){ | |
count++; | |
var classEven = ''; | |
var classOdd = ''; | |
var classThird = ''; | |
var classFourth = ''; | |
if(0 == count%2){ | |
classEven='even'; | |
$(this).addClass(classEven); | |
} | |
if(1 == count%2){ | |
classOdd='odd'; | |
$(this).addClass(classOdd); | |
} | |
if(0 == count%3 && false == $(this).hasClass('first')){ | |
classThird='third'; | |
$(this).addClass(classThird); | |
} | |
if(0 == count%4 && false == $(this).hasClass('first')){ | |
classFourth='fourth'; | |
$(this).addClass(classFourth); | |
} | |
}); | |
}; | |
// use example | |
// stripe secondary-menu | |
stripe('.secondary-menu > ul li'); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment