Add Javascript String.trim() Support for Older Browsers
String.prototype.trim = typeof (String.prototype.trim) != "undefined" ?
String.prototype.trim :
function() { return this.replace(/^\s\s*/, '').replace(/\s\s*$/, ''); };
Most newer browsers support " foobar ".trim()
--> "foobar"
, however older browsers (IE 7 etc) need a little help. :)
Written by Jason Seney
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Web-development
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#