jQuery 如何使用jquery更改元素的css
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10334239/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change css of element using jquery
提问by sachinjain024
I have defined a CSS property as
我已经定义了一个 CSS 属性
#myEltId span{
border:1px solid black;
}
On clicking a button, I want to remove its border.
单击按钮时,我想删除其边框。
$('#button1').click(function() {
// How to fetch all those spans and remove their border
});
回答by David says reinstate Monica
Just use:
只需使用:
$('#button1').click(
function(){
$('#myEltId span').css('border','0 none transparent');
});
Or, if you prefer the long-form:
或者,如果您更喜欢长格式:
$('#button1').click(
function(){
$('#myEltId span').css({
'border-width' : '0',
'border-style' : 'none',
'border-color' : 'transparent'
});
});
And, I'd strongly suggest reading the API for css()
(see the references, below).
而且,我强烈建议您阅读 API css()
(请参阅下面的参考资料)。
References:
参考:
回答by felixyadomi
If you will use this several times, you can also define css class without border:
如果你会多次使用这个,你也可以定义没有边框的css类:
.no-border {border:none !important;}
and then apply it using jQuery;
然后使用 jQuery 应用它;
$('#button1').click(function(){
$('#myEltId span').addClass('no-border');
});