· javascript

Javascript: Internet Explorer 8 - trim() leads to 'Object doesn't support this property or method' error

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 URI: http://our.app/file.js

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!

  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket