I am trying to add a dynamically-generated number at the end of "myclass" in Jquery. So I want it to increment a number at the end like this:
myclass1
myclass2
myclass3
myclass4
I've tried a few times but have no clue what I'm doing. Any help would be great!
var f=1;for(var g=0;g<d.count;g++)for(var f=1; f<3; f++){e.append("<li class='myclass"+f+"'><a>"+f+"</a></li>");f++}
I am not sure what you are trying to do, but here's my take on it. Of course, you can be more specific on the jQuery selector.
var i = 1;
$('li').each(function(){
$(this).addClass('myclass'+i);
i++;
});
EDIT
Based on the code provided:
for(var f = 1; f < 5; f++){
e.append("<li class='myclass"+f+"'><a>"+f+"</a></li>");
f++;
}
来源:https://stackoverflow.com/questions/12610686/jquery-class-add-an-increment-to-it