1

I am using jquery 1.10.2 and the following call to my dialogOpen function works fine in IE9+ but I am getting the following error in IE8:

Object does not support this property or method. Any ideas ?

dialogOpen($(this).attr("id"), $(this).find(".tdStyle").html().trim(),     $(this).find(".tdQtyOnHand").html().trim(), $(this),  $(this).find(".tdPlantID").html().trim());

Thanks

3
  • 1
    $(this).find(".tdStyle").html().trim() .trim() is the problem. The error message should have made that obvious. Doing a little research on that method would indicate that it isn't supported in IE<9 Commented Jan 21, 2014 at 18:13
  • @KevinB IE8's error messages aren't terribly helpful. It simply states that Object does not support this property or method. It could have been any dereference point (a .) in that line, not necessarily .trim(), as far as what we can glean directly from the error message. Obviously someone familiar with this kind of error, and jQuery chaining, can spot pretty quickly that it's likely .trim(), but that requires experience. Commented Jan 21, 2014 at 18:19
  • Kevin B and ajp15243 thank you for the responses. Commented Jan 21, 2014 at 18:22

1 Answer 1

4

.html() returns a String object and IE doesn't support the .trim() method on String, fortunately jQuery provides an alternative, $.trim(String). You can also add it yourself (but honestly with jQuery already loaded why would you) by following this exhaustive article (which would allow you to keep your original code entirely unmodified):

if (!String.prototype.trim) {
  String.prototype.trim = function () {
    return this.replace(/^\s+|\s+$/gm, '');
  };
}
Sign up to request clarification or add additional context in comments.

8 Comments

That and it's IE8 ... the sooner the world stops supporting it the better :-P
True, maybe I should hush up about how to overcome IE 8 and just offer a link to browsehappy.com :) This missing method in IE bit me a few times
why ms do not prompt users to upgrade like everyone else I do not understand
@andrew, they FINALLY started to after IE 10 but yes it took way too long. I think I read a Joel on Software blog about how they were paranoid of breaking enterprise web apps, so they did everything to keep the platform as stable as possible (bugs and all)
@andrew some companies have a bunch of PCs with Windows XP, so we have to try to make things work in IE8.
|

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.