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?
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, ''); }; }
if you want you can add jquery and use $.trim(....) this will work..
$.trim(" hello ");
give you
"hello"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With