Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 257
Roger Barr Avatar asked Nov 30 '22 05:11

Roger Barr


2 Answers

IE doesn't have a trim method.

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

like image 38
SLaks Avatar answered Dec 04 '22 06:12

SLaks


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());
like image 186
Nick Craver Avatar answered Dec 04 '22 06:12

Nick Craver