Mark Needham

Thoughts on Software Development

Javascript: Internet Explorer 8 – trim() leads to ‘Object doesn’t support this property or method’ error

with 3 comments

We make use of the Javascript trim() function in our application but didn’t realise that it isn’t implemented by Internet Explorer until version 9.

This led to the following error on IE8 when we used it:

Message: Object doesn’t support this property or method
Line: 18
Char: 13
Code: 0

There’s a stackoverflow thread suggesting some different ways of implementing your own ‘trim()’ method but since we’re using jQuery already we decided to just use the ‘$.trim()’ function from there.


var cleaned = ourString.trim();


var cleaned = $.trim(ourString);

I’m sure I must have come across this before but I don’t remember when!

Be Sociable, Share!

Written by Mark Needham

September 13th, 2011 at 1:33 pm

Posted in Javascript

Tagged with

  • Woulda been WAY cooler if you solved this with replacing the prototype trim() function (if it didn’t exist).

  • I found an interesting post which describes loads of different ways you can implement trim() –¬† – doesn’t seem worth reinventing the wheel if it already exists in jQuery thought?

  • SD4KSB

    $.trim is not working in IE11 and now i’m having a dilemma of making it work in IE8 and IE11