(这是在chrome扩展中使用内容脚本)
我需要覆盖网页标记为!important的一些css属性。这个是可能的吗?
例如,如果我想去掉标记为重要的边框:
$(".someclass").css('border','none'); //does not work发布于 2012-08-15 09:31:18
这就是了:
$( '.someclass' ).each(function () {
this.style.setProperty( 'border', 'none', 'important' );
});现场演示: http://jsfiddle.net/Gtr54/
元素的style对象的.setProperty方法使您能够传递表示优先级的第三个参数。因此,您正在用自己的!important值覆盖!important值。据我所知,不可能用jQuery设置!important优先级,所以您唯一的选择就是内置的.setProperty方法。
发布于 2014-09-13 07:34:38
您还可以执行以下操作:
$(".someclass").css("cssText", "border: none !important;");发布于 2017-11-15 17:02:17
这应该会有帮助。
$(".someclass").attr("style","border:none!important");已更新,以便不会覆盖所有样式:
var existingStyles = $(".someclass").attr("style");
$(".someclass").attr("style", existingStyles+"border:none!important");https://stackoverflow.com/questions/11962962
复制相似问题