Sunday, May 19, 2024
11
rated 0 times [  17] [ 6]  / answers: 1 / hits: 37430  / 12 Years ago, wed, june 27, 2012, 12:00:00

Whenever I use the trim() function on a string, it works fine with Chrome and Firefox but I get an error in IE8 saying :




Object doesn't support this property or method




Can anyone tell me why this happens and if there is a work around?


More From » internet-explorer

 Answers
38

IE8 doesn't support the trim function.
Here's a polyfill:



if(typeof String.prototype.trim !== 'function') {
String.prototype.trim = function() {
return this.replace(/^s+|s+$/g, '');
};
}

[#84637] Tuesday, June 26, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
albert

Total Points: 652
Total Questions: 105
Total Answers: 108

Location: Pitcairn Islands
Member since Fri, Oct 15, 2021
3 Years ago
;