Roger Barr
Roger Barr

Reputation: 41

Why does Internet Explorer not like this jQuery?

While debugging some jQuery that is not working in IE, I found this error message:

var item = $("#item_"+ itemArray[itemIndex]).find('a').text().trim();

Object doesn't support this property or method (script.js, line 100, character 2)

The character 2 doesn't make sense to me. Based on the text displayed character 2 would be the letter a in var but of course that doesn't make any sense.

(Should I not use var?)

I know that jQuery is working to some extent or the script would not have been able to get this far on my page.

Upvotes: 4

Views: 1857

Answers (2)

Nick Craver
Nick Craver

Reputation: 630349

IE doesn't have String.trim(), you'll need $.trim() (which uses native trim if available, emulates it in IE), like this:

var item = $.trim($("#item_"+ itemArray[itemIndex]).find('a').text());

Upvotes: 19

SLaks
SLaks

Reputation: 887245

IE doesn't have a trim method.

Instead, you can call jQuery.trim(...).

Upvotes: 3

Related Questions