Skip to content

Instantly share code, notes, and snippets.

@micha149
Created February 22, 2011 09:42
Show Gist options
  • Save micha149/838423 to your computer and use it in GitHub Desktop.
Save micha149/838423 to your computer and use it in GitHub Desktop.
Adding classes to first and last columns via jQuery
for (var i = 0; i < teaserData.length; i++) {
// Create teaser markup
var teaser = $('<div/>').addClass('teaser');
// ...
// Constructing the teaser
// ...
teaser.appendTo(container);
// Marks the first and last column by a 3 column layout
if (teaser.is(':nth-child(3n-2)')) {
teaser.addClass('firstColumn');
} else if (teaser.is(':nth-child(3n)')) {
teaser.addClass('lastColumn');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment