如何只删除一个样式属性与jquery [英] how to remove only one style property with jquery

查看:87
本文介绍了如何只删除一个样式属性与jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个div与此属性 style = - moz-user-select:none; position:static!important;
我需要删除 -moz-user-select
尝试使用$(selector).css()但是我不知道什么值因为它是无。

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".

推荐答案

css()说,将style属性设置为空字符串将会删除该属性,如果它不驻留在样式表中:

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:


将样式属性
的值设置为空字符串 - 例如
$('#mydiv')。css('color','') - 从元素中移除
b已经直接应用,
无论是在HTML样式属性,
通过jQuery的 .css()方法,或
通过直接
样式属性的DOM操作。但它不会,
删除已应用的样式
在样式表中有一个CSS规则或
< style> 元素。

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆