2012-12-19 65 views
0
<span class="stMainServices st-facebook-counter" style="background-image: url(http://w.sharethis.com/images/facebook_counter.png);">&nbsp;<img src="http://w.sharethis.com/images/check-big.png" style="position: absolute; top: -7px; right: -7px; width: 19px; height: 19px; max-width: 19px; max-height: 19px; display: none;"></span> 

我不能用我自己的形象改變的背景圖像(facebook_counter)。 我試圖通過使用 .css(「background-image」,「url ...」)和.attr(「style」,「new style」)來改變它,但也許我使用的選擇器部分是錯誤的。sharethis jQuery的背景圖像改變

此外,我通過在wordpress安裝中使用wp socializer來獲得此代碼。 謝謝

+1

你正在使用什麼選擇器? –

+0

似乎在這裏工作..'.css()'應該工作http://jsfiddle.net/GadTt/ –

回答

0

這是因爲CSS優先。內聯樣式(在標記中使用style="blah"聲明)的優先級高於樣式表中的項目。

您可以使用樣式上的!important標誌覆蓋它,但是this is considered bad practice

.st-facebook-counter 
{ 
    background-image: url('someotherimage.jpg') !important; 
} 
+0

我不這麼認爲..使用'.css()'直接操縱內聯樣式標記..所以圖像應該改變。 –

+0

不完全。如果您檢查元素,在您的jsfiddle中,它沒有應用您的JavaScript的CSS。如果你在css窗口添加: '.stMainServices {background-image:none!important; } CSS甚至勝過jQuery。 –

+0

此外,爲什麼在JS中你可以輕鬆處理CSS? –