If the div with id has specific text, delete another div

if the div with id has specific text, delete another div.

<script language="javascript"> 
var text = $('#div_with_dynamic_text').text();
var comparingText = 'THE_TEXT'
if(text == comparingText){
 $('#OTHER_DIV).css('display','none'); 
 }; 
</script>

<div id="div_with_dynamic_text">THE_TEXT</div>
<div id="OTHER_DIV"> some other div which needs to hide if certain text</div>
+3
source share
3 answers

You have missed a single Quote. This will work just fine.

<script language="javascript"> 
var text = $('#div_with_dynamic_text').text();
var comparingText = 'THE_TEXT'
if(text == comparingText){
 $('#OTHER_DIV').css('display','none'); 
 }; 
</script>
+4
source

Single quote missing: Change this:

$('#OTHER_DIV).css('display','none'); 

To:

$('#OTHER_DIV').css('display','none'); 
+1
source

Simpler approach

if($("div:contains('THE_TEXT')").length>0){
$('#OTHER_DIV').css('display','none');
}
0
source

All Articles