javascript - 从样式中删除背景图像

标签 javascript jquery css background-image

如何从元素样式中删除背景图像。我不想将它设置为无或 0。我想完全删除它。它与在另一个类中定义的 moz-linear-gradient 冲突。

<div style="background-image:url(http://domain.com/1.jpg); width:100px" class="mozgradient"></div>

最佳答案

你试过吗:

$(".mozgradient").css("background", "");

将背景设置为空字符串应该会删除内联样式,以便类和其他样式表设置生效,但它不应影响其他内联设置的样式,如 width。 (在这种情况下,将它从具有 mozgradient 类的所有元素中删除可以防止您正在谈论的冲突。)

来自 the jQuery .css() doco :

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.

关于javascript - 从样式中删除背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8032540/

相关文章:

javascript - 将元素拆分为列,每列包含特定数量的元素(html、css、javascript)

javascript - Rails 中带有 'Next' 和 'Previous' 按钮的表单 (Javascript)

javascript - css 切换 vs. css 改变

javascript - 将 MediaElementAudioSourceNode 转换为 AudioBufferSourceNode

Javascript 数据集

javascript - 填充由 jquery 生成的输入文本字段后启用按钮

javascript - jQuery 选择多个选项只选择最后一个值

javascript - 如何使用 jQuery 验证插件忽略输入字段的 "remote"验证

javascript - 您可以像将事件添加到 arb 节点和选择器一样分配可拖动吗?

javascript - 图表js将米平方/上标放在y轴上