15

trim() javascript function not working in IE7 however it' working fine in all other version and all browser. what should be issue with IE7 or how i can resolve this?

$("#Email").val().trim()

IE7 gives error

Thanks in advance.

2 Answers 2

29

IE doesn't support String.prototype.trim() until IE9.

It looks like you're using jQuery, so you can use $.trim() instead.

$.trim($("#Email").val())
2
  • thanks it's working fine in IE7 now however$("#Email").val().trim() was working on IE9 (probably in all above IE7)
    – Arun Rana
    Feb 1, 2012 at 5:45
  • @ArunRana: Yes, IE9 works. I didn't think IE8 had .trim() though. Glad you got it working.
    – user1106925
    Feb 1, 2012 at 13:48
1

The val() method doesn't always return a string. If the selected item is an option it can return an array which doesn't support trim. Have you checked the type of val() to see if it's actually a string?

Note: As others have pointed out trim isn't supported on IE7 even if this is a string. Need at least IE9.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.