Awais Qarni
Awais Qarni

Reputation: 18016

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 id
$("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

Upvotes: -1

Views: 130

Answers (2)

David Thomas
David Thomas

Reputation: 253506

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'} );

Upvotes: 4

lonesomeday
lonesomeday

Reputation: 238115

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.

Upvotes: 4

Related Questions