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');
  }
});
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><spanid="mess"style="visibility:visible;"><textid="tex">Message sent !</span></span>

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