2011-09-19 64 views
0

嗨我正在使用以下代碼通過jQuery應用css的多個屬性。我的代碼是這個jQuery代碼有什麼問題

$("div:contains('Awais')").css({text-decoration : 'underline', cursor : 'pointer'}); 

我得到JavaScript錯誤

missing : after property id 
$("div:contains(John)").css({text-dec...: 'underline', cursor : 'pointer'}); 

但是當我remoce text-decoration屬性錯誤消失。什麼是錯的代碼

+0

重新標記了這個問題。它與jQuery或選擇器無關。 –

+0

@Felix Kling Thanks dude –

回答

4

text-decoration是一個無效的屬性名稱,除非它是用引號括起來作爲一個字符串:

$("div:contains('Awais')").css({'text-decoration' : 'underline', cursor : 'pointer'}); 

對象屬性必須用引號括起來,除非它們是有效的JavaScript標識符。這是在對象文字,也爲使用點符號訪問聲明真實的(所以object.text-decoration無效

4

不能在JavaScript中使用未加引號的連字符,修改text-decoration使用textDecoration

$("div:contains('Awais')").css({textDecoration : 'underline', cursor : 'pointer'}); 

或者引用它:

$("div:contains('Awais')").css({'text-decoration' : 'underline', cursor : 'pointer'});