Skip to content

Instantly share code, notes, and snippets.

@vdchristelle
Created October 28, 2013 15:48
Show Gist options
  • Save vdchristelle/7199273 to your computer and use it in GitHub Desktop.
Save vdchristelle/7199273 to your computer and use it in GitHub Desktop.
Add striping (odd even classes) in jQuery - stripe
/*
* 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