2

Not sure why I got this error :

Object doesn't support property or method 'trimLeft' when browse with IE

My code is :

var checkTrimLeadingWhiteSpace = function(str) {
    if (str && ignoreLeadingWS) {
        return str.trimLeft();
    }

    return str;
};
Zakaria Acharki
  • 66,747
  • 15
  • 75
  • 101
Eva Cheung
  • 119
  • 1
  • 4
  • 14

2 Answers2

1

As MDN suggests the trimLeft function is non standard and should be avoided without a fallback.

However, you can write this:

var checkTrimLeadingWhiteSpace = function(str) {
   if (str && ignoreLeadingWS) {
     return str.replace(/^\s+/, "");
   }
   return str;
};

replace(/^\s+/, "") will remove all whitespaces in the beginning of the string.

Adam Wolski
  • 5,448
  • 2
  • 27
  • 46
0

trimLeft() : (Non-standard) This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

The IE Not support trimLeft() method also you shouldn't use the non-standard functionnalities as the official documentation says.

You may search for Left Trim in Javascript.

Hope this helps.

Source.

Community
  • 1
  • 1
Zakaria Acharki
  • 66,747
  • 15
  • 75
  • 101