Reputation: 918
Can anyone explain why this syntax does not work in Safari or Internet Explorer:
$('#something').attr({src: src_url, class:class_name});
IE, "Expected indentifier, string or number". And why do they require src and class to be strings like:
$('#something').attr({'src': src_url, 'class': class_name});
Thanks
Upvotes: 0
Views: 514
Reputation: 23943
From the documentation:
WARNING: When setting the 'class' attribute, you must always use quotes!
Upvotes: 1
Reputation: 10598
this is directly from the jQuery API docs:
When setting multiple attributes, the quotes around attribute names are optional.
WARNING: When setting the 'class' attribute, you must always use quotes!
Note: Internet Explorer does not allow you to change the type attribute of an or element.
Upvotes: 0
Reputation: 700252
The src
property should work without apostrophes, but class
is a reserved keyword so it can't be used as an identifier, it has to be a string.
Upvotes: 0