2016-06-16 42 views
-1

本页面有图片http://www.robertsroofing.com/services-view/leak-repair/特别是照片上方的橙色水滴图标。我想隐藏这(显示:无),但似乎无法通过CSS目标。所以我也尝试在页面底部添加一些JavaScript,但是这也不起作用。也许它没有针对性,但我觉得我尝试了一切。如何覆盖显然由javascript设置的内联样式?

<article id="post-1975" class="post__holder post-1975 services type-services status-publish has-post-thumbnail hentry"> 
    <figure class="featured-thumbnail thumbnail large"><img src="http://www.robertsroofing.com/wp-content/uploads/2014/11/icon-leak-tile.png" alt="Reliable Commercial Roof Leak Repair" style="display: inline;"></figure> 
</article> 
    <script> 
$(document).ready(function(){ 
$('.type-services .thumbnail img').attr('style','display: none'); 
}) 
</script> 

因为这个模板是与其他内容共享的,所以我需要专门定位父类型服务类。我只需要使用.type-services类时隐藏的图像。

+0

请在你的问题,而不是链接到网页上的相关标记 - 参见[东西在我的网站或项目不工作。我可以只是粘贴一个链接?](http://meta.stackoverflow.com/questions/254428/something-in-my-web-site-or-project-doesnt-work-can-i-just-paste -a-link-to-it) –

+1

您的选择器中有错字。不知道这是你的问题。 'thumnail' – sma

+0

你已经使用'.thumnail'丢失'b' – McNab

回答

0

元素的嵌入式样式为display: inline;。这就是为什么你的CSS覆盖不起作用。无论您的选择器具体如何,内联样式始终优先于CSS规则。

inline style

有2种方法可以解决这个问题。 1是在你的CSS,只需添加!important迫使风格的控制装置:

article.type-services figure.thumbnail > img { display: none !important; } 

,或者,如果你想坚持使用jQuery的方法,解决您的选择来定位正确的类 - 你有一个错字“缩略图”。另外,你应该使用'css'函数,而不是完全覆盖'style'属性。

$('.type-services .thumbnail img').css('display', 'none');

或只使用hide方法

$('.type-services .thumbnail img').hide();

+0

男人,我错过了添加重要!到CSS。只是看着它太长,而在昨晚旅行的汽车中,尽管如此,哈哈。感谢你对它的新鲜目光。我从来没有新的内联风格来自哪里。它正在应用于DOM准备。 – Andrew