Try this code to add classes to existing html tags
$('.msgpvtstyle ').each(function() { $('.msgpvtstyleme:first-child' , $(this)).addClass('first'); $('.msgpvtstyleme:last-child' , $(this)).addClass('last'); $('.msgpvtstyleme:not(:first-child):not(:last-child)' , $(this)).addClass('middle'); });
Nihar sarkar
source share