Change color of divs of the same class according to the text that contains them (Jquery)

0

I have several divs with the same class, inside it has the text "FREE" or "PAYMENT", in which it contains the text "FREE" that has one color and "PAYMENT" another. I used :contains() but since they are divs of the same class they all have the same color.

    
asked by anonymous 14.01.2017 / 17:20

1 answer

0

You can use the tag itself: contains, 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 fiddle:

link

I hope I have helped.

Doubts are available.

    
14.01.2017 / 18:09