Trim function for older IE browsers
July 27th 2013
2759

Trim function for older IE browsers

If you use jQuery, you’ve certainly came across the trim() function. It’s the quickest and painless way to remove the white space from the beginning and end of a string. However as much as jQuery tries to cover cross-browser compatibility, there’s just this little that always gets missed out on.

Here’s an example of the jQuery trim function:

However, this simple function will error out if used on the older Internet Explorer browsers. To solve this all you need to do is post the function below anywhere in your script file and all your javascript errors (related to the trim function of course) should disappear.

And that’s all. Get coding and as usual, should you need any further information feel more than welcome to use the comments section below or contact us directly at blog@kartogram.co.uk

Regards,

SD

Back To Blog