1

一見、これは簡単なはずですが、私はすでにしばらくの間それを見つけました。

<h2>特定のテキストが表示されたときにのみタグを非表示にしようとしています。CMS がタグを生成します。HTML は次のようになります。

<div class="Block Moveable Panel" id="BrandContent">
  <h2>All Brands</h2>
  <div class="BlockContent">
     BRANDS LISTED HERE...
  </div>
</div>

「すべてのブランド」が h2 タグに含まれている場合、タグを削除または非表示にします。

以下のコードのいくつかの組み合わせを試しましたが、成功しませんでした:

if($('#BrandContent > div.h2:contains("All Brands")').length > 0) {
    $('#BrandContent h2').css('visibility', 'hidden')
}

 $('#BrandContent h2').remove(":contains('All Brands')");

ご提案いただきありがとうございます。M

4

4 に答える 4

1

試す

$('#BrandContent > h2:contains("All Brands"))
于 2013-08-07T05:19:53.870 に答える
1

Try this selector

$('#BrandContent > h2:contains("All Brands")').css('visibility', 'hidden')

Check Fiddle

You were using the id Attribute but using the class selector

id="BrandContent">

Your first try had a small mistake

$('#BrandContent > div.h2

You were looking for a div which has class .h2 which is not present in your HTML

于 2013-08-07T05:18:08.000 に答える
1

あなたのセレクターは間違っています -

それはこのようにする必要があります -

$('#BrandContent > h2:contains("All Brands")')
于 2013-08-07T05:19:15.847 に答える
0

「BrandContent」が id であり、クラスとして使用しているため、間違ったセレクターを使用しています。したがって、次のようになります。

$('#BrandContent > h2:contains("All Brands")').hide();  

JSFIDDLE デモ

于 2013-08-07T05:20:20.477 に答える