Skip to content Skip to sidebar Skip to footer

Change Color Of Span Tag Depending On Value

I want to change the color of the message variable in the following HTML: {{ message }}<

Solution 1:

Lets use contains selector.

$(document).ready(function() {
  if ($('#tex:contains("Message sent !")').length) {
    $('#tex').css('color', 'green');
  } else {
    $('#tex').css('color', 'red');
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span id="mess" style="visibility:visible;">
  <text id="tex">Message sent !</span>
</span>

Post a Comment for "Change Color Of Span Tag Depending On Value"