I'm faced with the challenge of coloring a table based on its values. For instance, if a cell contains 150%, it should be red; if it's 50%, it should be green. Unfortunately, the text in my table has spaces and '%' symbols scattered throughout. How can I remove these unwanted characters?
This is what I've tried so far:
<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
It seems I failed to mention that some percentages include decimal points, like "50.89%". Current solutions are converting this to "5089" which isn't desired. How can I retain the decimal point?