是否有可能重写/删除背景:无!重要与jQuery? [英] Is it possible to override / remove background: none!important with jQuery?

查看:103
本文介绍了是否有可能重写/删除背景:无!重要与jQuery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个元素应该有一个背景图片,但它在我无法访问/修改的样式表中给出以下样式:

 #an-element li {
background:none!important;
}

是否可以使用jQuery撤消该样式?我试图用两种方式添加 background:inhert!important 和jQuery:通过添加一个内联样式,并删除一个应用的样式。两者都不起作用。



这是一个说明问题的小提琴: http:// jsfiddle .net / 9bJzk / 1 /



更新:我有错误的连线,请再试一次。



UPDATE 2:我无法编辑样式表。我改变了标题,现在更清楚。我不得不这样做与jQuery,因为我不能控制CSS文件的加载顺序,但可以运行jQuery onload。



更新3:我不能明确用一个更精确的CSS选择器像#an-element .image-list li 来设置'kitten'pic(见小提琴)被写出在飞行。 jsFiddle只是一个例子。为了使它更清楚:可以用PURE jQuery撤销 background:none 的效果,而不是编辑任何样式表。非常感谢您的支持!

解决方案

  div {background:none!important} $ b div {background:red; } 

是透明的。

  div {background:none!important} 
div {background:red!important; }

是红色的。



重要的是可以覆盖另一个!重要的。



如果您不能编辑CSS文件,您仍然可以在head标签中添加另一个或样式标签。 >

I have an element which should have a background image, but it's been given the following style in a stylesheet that I'm not able to access/modify:

#an-element li {
  background: none !important;
}

Is it possible to undo that style with jQuery? I've tried to add background: inhert!important with jQuery in two ways: by adding an inline style, and by removing an applied style. Neither work.

Here is a Fiddle illustrating the problem: http://jsfiddle.net/9bJzk/1/

UPDATE: I had the wrong fiddle link, please look again.

UPDATE 2: I cannot edit the stylesheet. I've changed the title to be more clear now. I have to do this with jQuery as I can't control the loading order of the CSS files, but can run jQuery onload.

UPDATE 3: I can't explicitly set the 'kitten' pic (see the fiddle) with a more accurate CSS selector like selector like #an-element .image-list li as some are suggesting as those images are being written out on the fly. The jsFiddle was just an example. To make it clearer still: Can the effects of the background: none be undone with PURE jQuery and NOT editing of any stylesheets. Thanks for sticking with this!

解决方案

div { background: none !important }
div { background: red; }

Is transparent.

div { background: none !important }
div { background: red !important; }

Is red.

An !important can override another !important.

If you can't edit the CSS file you can still add another one, or a style tag in the head tag.

这篇关于是否有可能重写/删除背景:无!重要与jQuery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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