var length = $(this).text().length; if(length > 20) { class_name = '1'; } else if(length > 30) { class_name = '2'; } else { class_name = '3'; }