Translate

Friday 6 June 2014

.trim() in JavaScript not working in IE

Add the following code to add trim functionality to the string.
if(typeof String.prototype.trim !== 'function') {
  String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, ''); 
  }
}

No comments:

Post a Comment