Theopile
Theopile

Reputation: 918

IE and Safari jQuery Syntax Error

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

Answers (3)

Ken Redler
Ken Redler

Reputation: 23943

From the documentation:

WARNING: When setting the 'class' attribute, you must always use quotes!

Upvotes: 1

Kris Ivanov
Kris Ivanov

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

Guffa
Guffa

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

Related Questions