Skip to content

Instantly share code, notes, and snippets.

@tron1point0
Created February 19, 2014 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tron1point0/9093495 to your computer and use it in GitHub Desktop.
Save tron1point0/9093495 to your computer and use it in GitHub Desktop.
(function() {
var color_stuff = function(selector,classes) {
var nth_of_type = function(len,i) {
return ':nth-of-type(' + len + 'n+' + i + ')'
};
var nested = function(c) {
return function() {
var cs = classes.filter(function(e) { return e !== c });
for (var i = 0; i < cs.length; i++)
$(this).children(selector + nth_of_type(cs.length,i))
.each(nested(cs[i]));
$(this).addClass(c);
};
};
nested(classes[0]).call(this);
};
color_stuff.call($('#comments'),'div',['color-1', 'color-2', 'color-3']);
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment