![](/img/trans.png)
[英]Using jQuery to change style of clicked element and removing that style from other elements with same class
[英]jQuery change CSS background of clicked element from many elements with same .class
我正在研究一個簡單的jQuery腳本,我想更改clicked元素的背景顏色。
所以這是我的代碼:
<dt>
<input id="p_method_banktransfer" value="banktransfer" type="radio" name="payment[method]" title="Bank Payment" class="radio validation-passed" autocomplete="off"/>ev
<label for="p_method_banktransfer">Банков превод </label>
</dt>
我有很多<dt>...</dt>
標簽
這是<dt>
的CSS:
.opc-wrapper-opc .payment-block dt {
background: #3399CC;
border-radius: 2px;
margin: 0px 0px 13px;
position: relative;
}
所以實際上似乎我在單擊標簽或輸入,但是我要更改的背景是該dt
元素的。
我該怎么做?
$('body').on('click', 'dt', function(){
$(this).css('background','red'); // substitute your color for red
});
更新
要將所有<dt/>
OTHER(單擊的內容除外)更改回原始顏色,請執行以下操作:
$('body').on('click', 'dt', function(){
$('dt').not(this).css('background', '#3399CC'); // change back to original color
$(this).css('background','red'); // substitute your color for red
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.