如何使用jQuery仅删除一个样式属性? [英] How to remove only one style property with jQuery?
问题描述
我有一个具有此属性的div style ="-moz-user-select:none;position:static!important;"
.我需要删除 -moz-user-select
尝试过 $(selector).css()
,但我不知道要设置什么值,因为它是"none"
.
a>表示将style属性设置为空字符串将删除该属性(如果它不存在于样式表中):
设置样式属性的值到一个空字符串-例如
$('#mydiv').css('color','')
-删除元素中的该属性(如果有)已经直接应用了,是否在HTML样式属性中,通过jQuery的.css()
方法,或通过对DOM的直接操作样式属性.但是,它没有删除已应用的样式在样式表中使用CSS规则或< style>
元素.
由于您的样式是内联样式,因此您可以编写:
$(selector).css(-moz-user-select",");
I have a div with this property style="-moz-user-select:none; position:static !important;"
.
I need to remove the -moz-user-select
Tried with $(selector).css()
but I don't know what value to set because it's "none"
.
The documentation for css() says that setting the style property to the empty string will remove that property if it does not reside in a stylesheet:
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 the style property. It does not, however, remove a style that has been applied with a CSS rule in a stylesheet or<style>
element.
Since your styles are inline, you can write:
$(selector).css("-moz-user-select", "");
这篇关于如何使用jQuery仅删除一个样式属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!