jQuery addClass() Function Example

By Sam Deering

jQuery code snippet to add a css style for elements with the .addcss class but use a different style for first, second and third elements (multiples of 3).

	//value of n can be changed to mutiples of whatever you wish
	var n = i % 3;
	n == 0 ? 'cssstyle1' :
	n == 1 ? 'cssstyle2' :
	n == 2 ? 'cssstyle3' : '');



Because We Like You
Free Ebooks!

Grab SitePoint's top 10 web dev and design ebooks, completely free!

Get the latest in JavaScript, once a week, for free.