如果我使用以下方法在特定元素上设置 CSS 值:
$('#element').css('background-color', '#ccc');
我希望能够取消设置特定于元素的值并使用级联值,按照以下行:
$('#element').css('background-color', null);
但该语法似乎不起作用——是否可以使用其他语法?
编辑:该值不是从父元素继承的——原始值来自元素级选择器。抱歉造成任何混淆!
最佳答案
来自jQuery docs :
Setting the value of a style property to an empty string — e.g.
$('#mydiv').css('color', '')
— removes that property from an element if it has already been directly applied, whether in the HTML style attribute, through jQuery's.css()
method, or through direct DOM manipulation of thestyle
property. It does not, however, remove a style that has been applied with a CSS rule in a stylesheet or<style>
element.
关于jquery - 如何使用 jQuery 取消设置元素的 CSS 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/490910/