覆盖!用css或jquery重要 [英] Overriding !important with css or jquery

查看:116
本文介绍了覆盖!用css或jquery重要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(这是使用Chrome扩展程序中的内容脚本)

(This is using content scripts in a chrome extension)

我需要覆盖一些CSS属性,网页标记为!important 。这是可能吗?

I need to overwrite some css properties that the webpage has labeled as !important. Is this possible?

例如,如果我想摆脱标记为重要的边框:

For instance, if I want to get rid of the border that is labeled important:

$(".someclass").css('border','none'); //does not work


推荐答案

p>

Here you go:

$( '.someclass' ).each(function () {
    this.style.setProperty( 'border', 'none', 'important' );
});

在线演示 http://jsfiddle.net/Gtr54/

.setProperty 方法的元素的 style 对象使您能传递第三个参数表示优先级。所以,你重写一个!重要的价值与你自己的!重要的价值。据我所知,它是不可能设置!重要的优先级与jQuery,所以你唯一的选择是内置的 .setProperty 方法。

The .setProperty method of an element's style object enables you to pass a third argument which represents the priority. So, you're overriding an !important value with your own !important value. As far as I know, it is not possible to set the !important priority with jQuery, so your only option is the built-in .setProperty method.

这篇关于覆盖!用css或jquery重要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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