如果带有id的div有某些文本删除其他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>
答案 0 :(得分:4)
<script language="javascript">
var text = $('#div_with_dynamic_text').text();
var comparingText = 'THE_TEXT'
if(text == comparingText){
$('#OTHER_DIV').css('display','none');
};
</script>
答案 1 :(得分:1)
缺少单引号: 改变这个:
$('#OTHER_DIV).css('display','none');
要:
$('#OTHER_DIV').css('display','none');
答案 2 :(得分:0)
更简单的方法
if($("div:contains('THE_TEXT')").length>0){
$('#OTHER_DIV').css('display','none');
}