I have a simple if else statement that will color a number based on it's value.
Can anyone explain why the below always results in red?
$(document).ready(function() {
// the following will select all elements with class "deltadiff"
// if the element has a '-', it will assign a 'red' class, else it will assign the 'green class'
if ($(".deltadiff:contains('-')"))
$(".deltadiff").addClass('red');
else $(".deltadiff").addClass('green');
}
)
.red {
color: red;
}
.green {
color: green;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<font class="deltadiff" style="font-size:10px; vertical-align:super;"> -120</font>
<font class="deltadiff" style="font-size:10px; vertical-align:super;"> 120</font>
<font class="deltadiff" style="font-size:10px; vertical-align:super;"> 5</font>
<font class="deltadiff" style="font-size:10px; vertical-align:super;"> -7</font>