Sunday, February 17, 2013

java script- trim function problem in ie8 solution

Problem: Java Script trim() function doesn't work in IE8 browser.

Error Message: Object doesn't support this property or method 

As you know, whenever you use trim() function of java script, it works fine with Chrome and FireFox browsers but you get an error with Internet Explorer (IE8).


$(document).ready(function () {

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 fine

$.trim(" hello ");

gives you



Anonymous said...

Woww that was strange. I juxt wrote an extremely long comment but
after I clicked submit myy commennt didn't appear.

Grrrr... well I'm not writing all that oover again. Anyhow, just wanted to say fantastic blog!

Take a look at my website webmarketing

Powered by Code Imagine