Colorize negative/positive numbers (jQuery)
问题 I'd like to color numbers in a table for better readability: green for positive (+00.00); red for negative (-00.00) and; black for default case (no sign) 回答1: Here ya go: $(document).ready( function() { // the following will select all 'td' elements with class "of_number_to_be_evaluated" // if the TD element has a '-', it will assign a 'red' class, and do the same for green. $("td.of_number_to_be_evaluated:contains('-')").addClass('red'); $("td.of_number_to_be_evaluated:contains('+')")