特定のテキストが含まれているかどうかに基づいて、(クラス名が同じである)他のクラスと異なるクラスのスタイルを設定しようとしています。私はクラスを追加することができましたが、私が直面している問題は、マスターのCSSクラスがそれを無効にしていることです。コードは、表示する:重複する名前にもかかわらず、divクラスがjQueryで別のCSSクラスを使用するように強制しますか?
HTML
<div id="master">
<div>
<div class="attributes">
<a href="#">Not important</a>
</div>
</div>
<div>
<div class="attributes">
<a href="#">Not important</a>
</div>
</div>
<div>
<div class="attributes">
<a href="#">Important Text and Other Stuff</a>
</div>
</div>
<div>
<div class="attributes">
<a href="#">Not important</a>
</div>
</div>
</div>
オリジナルCSS
jQueryの使用
#master div.attributes {
float: left;
font-size: 12px;
margin-top: 0px !important;
width: 330px;
clear: both;
}
.attributes {
color: #58585a !important;
font-size: 14px;
margin: -10px 0 0 !important;
}
$('div.attributes:contains("Important Text")').addClass('attributes2');
CSSは
.attributes2
{
clear: none;
float: right;
font-size: 12px;
margin-top: 0;
width: 330px;
}
だから正常に追加.attributes2を追加しました。しかし#master div.attributes CSSクラスがこれを却下され、それを使用しています。誰もこれを回避する方法を考えることができますか?私は無数のgoogle &スタック検索、幸運なことをした...私はHTML id &クラス名を編集する能力がないと言及する必要があります。しかし、私は& jQueryを編集することができます。
本当にありがとうございます。
ありがとう、素晴らしい!はい、今すぐcssでもっと読む必要があります。もう一度おかげで、これはそれをやった。 – Dware