To make valid class names (which can't start with a digit):
$("#main_list li").addClass(function() {
return("myItem" + $(this).index());
});
But, it sounds to me like you might rather be setting an id:
$("#main_list li").attr("id" function() {
return("myItem" + $(this).index());
});
Looking at Cris' (the original poster) comments to other answers, it sounds like what you want to do is to be able to extract the ordered position from the object at some later date. It might be easier to just put a data attribute on the object that represents it's order like this:
// put an attribute on each object that represents it's index so that's easier to get later
$("#main_list li").each(function(index){
$(this).data("pos", index);
});
Then later, you can access that data value with this:
item.data("pos");
This seems a lot cleaner to me than parsing a number out of class name that you have no other use for.
Example here: http://jsfiddle.net/jfriend00/RDvw2/.