user2547566
user2547566

Reputation: 23

Hide a class if the text in another class contains . . .

I am working with a form that has multiple steps, I would like to hide a span of text that has class .newtest applied to it if another class, .RegCurrent contains the text "Step 1 Selection".

<ol class="steps">
<li class="RegCurrent">Step 1 Selection</li>
<li class="notcurrent">Step 2 Selection</li>
<li class="notcurrent">Step 3 Selection</li>
</ol>

<div class="singleCol">
<span class="newtest">
<h1>some text</h1>
<p>some more text</p>
</span>
<p>some text and tables</p>
</div>

What I have tried:

<script>
$(document).ready(function() {
if( $('.RegCurrent:contains("Step 1 Selection")') {
$('.newtest').hide();
}
});
</script>

Upvotes: 1

Views: 198

Answers (2)

Thought Space Designs
Thought Space Designs

Reputation: 429

if($('.RegCurrent').text() == "Step 1 Selection"){
    $('.newtest').hide();
}

Upvotes: 0

Adil
Adil

Reputation: 148110

You have to use length with selector in condition, other wise you wont get false as you will get jQuery object event when selector does not return any object. You also missed the closing parenthesis of in condition.

Live Demo

$(document).ready(function() {
  if( $('.RegCurrent:contains("Step 1 Selection")').length) {
    $('.newtest').hide();
  }
});

Upvotes: 2

Related Questions