2016-06-16 41 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