Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery contains strings

I whant to add class on specific string but problem is that string starts with number 0.

This is my code I whant to add just on "0 BAM" class but when I add this Jquery he add class on all divs that have 0 and BAM, Like first one "290 BAM"

<div class="views-field-commerce-price"> 290  BAM</div>
<div class="views-field-commerce-price"> 0  BAM</div>
<div class="views-field-commerce-price"> 223  BAM</div>
<div class="views-field-commerce-price"> 490  BAM</div>

  $('.views-field-commerce-price:contains("0  BAM")').addClass('item-3');

Thank You!

like image 221
Edin Puzic Avatar asked Dec 10 '22 19:12

Edin Puzic


1 Answers

I think you need exact comparison, Here you can use .filter()

$('.views-field-commerce-price').filter(function(){
    return $(this).text().trim() == "0  BAM";
}).addClass('item-3');
like image 136
Satpal Avatar answered Dec 23 '22 09:12

Satpal