Reputation: 23
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
Reputation: 429
if($('.RegCurrent').text() == "Step 1 Selection"){
$('.newtest').hide();
}
Upvotes: 0
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.
$(document).ready(function() {
if( $('.RegCurrent:contains("Step 1 Selection")').length) {
$('.newtest').hide();
}
});
Upvotes: 2