Skip to content

Instantly share code, notes, and snippets.

@adrianrodriguez
Last active September 27, 2015 16:07
Show Gist options
  • Save adrianrodriguez/1295633 to your computer and use it in GitHub Desktop.
Save adrianrodriguez/1295633 to your computer and use it in GitHub Desktop.
Add incremental numbers as classes to an element.
$(function() {
var i = 0;
$(".foo:first-child").addClass("post-" + i);
$(".foo").each(function(){
$(this).addClass("post-" + i++);
});
//Another way of doing this:
$('#foo li').attr('id', function(i) { // Or class
return 'item'+(i+1);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment