Last active
September 27, 2015 16:07
-
-
Save adrianrodriguez/1295633 to your computer and use it in GitHub Desktop.
Add incremental numbers as classes to an element.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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