jQuery: JavaScript keywords and IE

Internet Explorer has some problems with handling JavaScript reserved keywords when these appear within a jQuery method. For example, suppose that you want to set a CSS class using the attr() method, like so:

$(element).attr({id: 'Test', class: 'Test'});

IE will simply throw an error, because class is a reserved word in JavaScript. To avoid this problem, you can either enclose the keyword between quotes or using another approach (in this case you can use addClass()).

2 thoughts on “jQuery: JavaScript keywords and IE”

Leave a Reply

Note: Only a member of this blog may post a comment.