$("ul > li > span").each(function() { var month = $(this).text().substr(0, 2); $(this).addClass('y' + month);});