what is wrong with this jquery code
Hi I am using following code for applying multiple attributes of css through jquery. My code is
$("div:contains('Awais')").css( {text-decoration : 'underline', cursor : 'pointer'} );
I get javascript error
missing : after property i开发者_JAVA百科d
$("div:contains(John)").css( {text-dec...: 'underline', cursor : 'pointer'} );
But When I remoce text-decoration
property the error vanishes. What is wrong with this code
text-decoration
is an invalid property name unless it's enclosed in quotes as a string:
$("div:contains('Awais')").css( {'text-decoration' : 'underline', cursor : 'pointer'} );
Object properties must be enclosed in quotes unless they are valid Javascript identifiers. This is true for declarations in object literals and also for accessing using the dot notation (so object.text-decoration
is invalid.
You can't use a hyphen unquoted in JavaScript, to modify text-decoration
use textDecoration
:
$("div:contains('Awais')").css( {textDecoration : 'underline', cursor : 'pointer'} );
Or quote it:
$("div:contains('Awais')").css( {'text-decoration' : 'underline', cursor : 'pointer'} );
精彩评论