如何使用jquery更改元素的css
我已经将CSS属性定义为
#myEltId span{ border:1px solid black; }
单击按钮,我想删除其边框。
$('#button1').click(function() { // How to fetch all those spans and remove their border });
只需使用:
$('#button1').click( function(){ $('#myEltId span').css('border','0 none transparent'); });
或者,如果您更喜欢长forms:
$('#button1').click( function(){ $('#myEltId span').css({ 'border-width' : '0', 'border-style' : 'none', 'border-color' : 'transparent' }); });
而且,我强烈建议您阅读css()
的API(参见下面的参考资料)。
参考文献:
-
css()
。
如果你将多次使用它,你也可以定义没有边框的css类:
.no-border {border:none !important;}
然后使用jQuery应用它;
$('#button1').click(function(){ $('#myEltId span').addClass('no-border'); });