1

I have a page with the following code:

<div class="box1">Free</div>
<div class="box2">$100</div>

I want to check the page and every time the "box1" div contains the text "Free" to remove entirely the "box2" div.

I tried something like that with jQuery

$('.box1("Free")') {
$('.box2').hide();
}

but doesn't work. What i 'm doing wrong?

JSFiddle Here

Designer
  • 875
  • 7
  • 26

3 Answers3

2

Use text() method to retrieve text from box1

if ( $('.box1').text() === 'Free' ) {
  $('.box2').hide();
}
Arkej
  • 2,221
  • 1
  • 14
  • 21
2

This snippet will be helpful:

if($('.box1').text() === "Free") {
  $('.box2').hide();
}
Ihor Lavs
  • 2,315
  • 2
  • 15
  • 26
0

Use this

$(document).ready(function (){
            $('.box1:contains(Free)') {
                 $('.box2').hide();
      }
   });

For more info. https://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_sel_contains

Negi Rox
  • 3,828
  • 1
  • 11
  • 18