Bookmark and Share

Tuesday, June 28, 2011

JavaScript Trim on Internet Explorer…

If you are writing scripts for firefox, chrome, safari and ie and you are using the trim function… don’t forget that IE does’n support it!

In order to enable it you need to add the script:

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


That’s all!