Arshad Arsal
Arshad Arsal

Reputation: 64

Change text color according to the text value in the column

I was trying to change the text color according to the value inside the td. Here is what I mean.

<table>
<tr>
<td class="value-text">Hello there</td>
<tr>
</table>

<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script>  
$( ".value-text:contains('Hello')" ).css( "color", "red" );
</script>

This method works only if it's a div. But I need it to work on a td. Can anyone help, please?

Upvotes: 0

Views: 454

Answers (1)

Captain Planet
Captain Planet

Reputation: 408

You code work fine when done with modifications. You can refer to this fiddle https://jsfiddle.net/qL96hmtc/

HTML code

<table>
<tr>
<td class="value-text">Hello there</td>
</tr>
</table>

JS code

$(document).ready(function(){
    $( ".value-text:contains('Hello')" ).css( "color", "red" ); 
})

Upvotes: 1

Related Questions