I have a table that I'm trying to color based on the values in the table. So, if the value in the table is 150%, the cell would be colored red. If the value in the table is 50%, the value would be colored green. However, for some reason, the actual text in the table has a multitude of spaces within them as well as a % symbol. How can I replace any spaces and '%' characters with nothing ('')?
Here is what I have that isn't working:
<script type="text/javascript">
$(document).ready(function () {
$('#myTable td.PercentMem').each(function () {
if ($(this).text().replace(/\s/g, '').replace('%', '') >= '100') {
$(this).css('background-color', '#ff0000');
}
else {
$(this).css('background-color', '#33cc33');
}
});
});
</script>
Thank you!
EDIT
I'm dumb. I forgot to include the fact that these percentages have a decimal point in them. So, what I'm really dealing with is something like "50.89%", and the solutions provided thus far convert that into "5089". How can I keep the decimal?
"9" > "100" == true.