Change color of Divs of the same class according to the text it contains in them (Jquery)

Asked

Viewed 147 times

0

I have several divs with the same class, inside them has the text "FREE" or "PAID", in which contains the text "FREE" need to have a color and "PAID" other. I used :contains() but how they are divs of the same class all the same colour.

1 answer

0


You can use the :contains tag itself, as an example I did.

$(document).ready(function(){

$("div.divLista:contains('FREE')").css("background","red");
$("div.divLista:contains('PAGO')").css("background","green");

});

Follow the code on the fiddle:

https://jsfiddle.net/nnksesdm/2/

I hope I’ve helped.

Doubt I’m at your disposal.

  • Man, thank you so much! It worked perfectly :D Thank you so much

  • Show!! do not forget to evaluate the question positively. ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.