[英]jQuery change CSS background of clicked element from many elements with same .class
I'm working on a simple jQuery script that i want to change the background color of the clicked element. 我正在研究一个简单的jQuery脚本,我想更改clicked元素的背景颜色。
So here is my code: 所以这是我的代码:
<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>
I have many <dt>...</dt>
tags 我有很多
<dt>...</dt>
标签
Here is the CSS of <dt>
: 这是
<dt>
的CSS:
.opc-wrapper-opc .payment-block dt {
background: #3399CC;
border-radius: 2px;
margin: 0px 0px 13px;
position: relative;
}
So actually it seems that i am clicking on the label or on the input but the background that i want to change is of that dt
element. 所以实际上似乎我在单击标签或输入,但是我要更改的背景是该
dt
元素的。
How i can make it ? 我该怎么做?
$('body').on('click', 'dt', function(){
$(this).css('background','red'); // substitute your color for red
});
UPDATE 更新
To change all <dt/>
OTHER than the clicked one back to the original color: 要将所有
<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.