Skip to main content

Bug Tracker

Side navigation

#9833 closed bug (wontfix)

Opened July 15, 2011 10:49AM UTC

Closed October 17, 2011 08:24PM UTC

`maxLength` property is buggy in IE8/IE9

Reported by: mathias Owned by:
Priority: low Milestone: None
Component: attributes Version: git
Keywords: Cc: addyosmani
Blocked by: Blocking:
Description

IE≤8 has a .maxlength property on <textarea> elements instead of .maxLength.

IE9 is even funnier and has none of these properties (!). Looks like we’re forced to fall back to .getAttribute() for that browser — I can’t think of any other solution.

propFix in jQuery maps $(el).prop('maxlength') to el.maxLength but that fails in IE8.

Test case: http://jsfiddle.net/mathias/Vc9ap/ tests $(el).prop('maxlength'), $(el).prop('maxLength'), and el.maxlength.

It should say 42,42,undefined. Results:

  • IE8: undefined,undefined,42
  • IE9: undefined,undefined,undefined (WTF)
  • IE10 and others get it right.

In my code, I’m using something like el.maxLength || el.maxlength || el.getAttribute('maxlength') now. It seems jQuery should do the same.

Attachments (0)
Change History (5)

Changed July 15, 2011 10:51AM UTC by mathias comment:1

cc: → addyosmani
component: unfiledattributes
description: IE≤8 has a `.maxlength` property on <textarea> elements instead of `.maxLength`. \ IE9 is even funnier and has none of these properties (!). Looks like we’re forced to fall back to `.getAttribute()` for that browser — I can’t think of any other solution. \ \ `propFix` in jQuery maps `$(el).prop('maxlength')` to `el.maxLength` but that fails in IE8. \ \ Test case: http://jsfiddle.net/mathias/Vc9ap/ tests `$(el).prop('maxlength')`, `$(el).prop('maxLength')`, and `el.maxlength`. \ It should say `42,42,undefined`. \ IE8: undefined,undefined,42 \ IE9: undefined,undefined,undefined (WTF) \ IE10 (and others) gets it right. \ \ In my code, I’m using something like `el.maxLength || el.maxlength || el.getAttribute('maxlength')` now.IE≤8 has a `.maxlength` property on <textarea> elements instead of `.maxLength`. \ IE9 is even funnier and has none of these properties (!). Looks like we’re forced to fall back to `.getAttribute()` for that browser — I can’t think of any other solution. \ \ `propFix` in jQuery maps `$(el).prop('maxlength')` to `el.maxLength` but that fails in IE8. \ \ Test case: http://jsfiddle.net/mathias/Vc9ap/ tests `$(el).prop('maxlength')`, `$(el).prop('maxLength')`, and `el.maxlength`. \ \ It should say `42,42,undefined`. Results: \ \ * IE8: undefined,undefined,42 \ * IE9: undefined,undefined,undefined (WTF) \ * IE10 and others get it right. \ \ In my code, I’m using something like `el.maxLength || el.maxlength || el.getAttribute('maxlength')` now. It seems jQuery should do the same.
status: newopen

Changed July 15, 2011 10:55AM UTC by mathias comment:2

description: IE≤8 has a `.maxlength` property on <textarea> elements instead of `.maxLength`. \ IE9 is even funnier and has none of these properties (!). Looks like we’re forced to fall back to `.getAttribute()` for that browser — I can’t think of any other solution. \ \ `propFix` in jQuery maps `$(el).prop('maxlength')` to `el.maxLength` but that fails in IE8. \ \ Test case: http://jsfiddle.net/mathias/Vc9ap/ tests `$(el).prop('maxlength')`, `$(el).prop('maxLength')`, and `el.maxlength`. \ \ It should say `42,42,undefined`. Results: \ \ * IE8: undefined,undefined,42 \ * IE9: undefined,undefined,undefined (WTF) \ * IE10 and others get it right. \ \ In my code, I’m using something like `el.maxLength || el.maxlength || el.getAttribute('maxlength')` now. It seems jQuery should do the same.IE≤8 has a `.maxlength` property on <textarea> elements instead of `.maxLength`. \ IE9 is even funnier and has none of these properties (!). Looks like we’re forced to fall back to `.getAttribute()` for that browser — I can’t think of any other solution. \ \ `propFix` in jQuery maps `$(el).prop('maxlength')` to `el.maxLength` but that fails in IE8. \ \ Test case: http://jsfiddle.net/mathias/Vc9ap/ tests `$(el).prop('maxlength')`, `$(el).prop('maxLength')`, and `el.maxlength`. \ \ It should say `42,42,undefined`. Results: \ \ * IE8: `undefined,undefined,42` \ * IE9: `undefined,undefined,undefined` (WTF) \ * IE10 and others get it right. \ \ In my code, I’m using something like `el.maxLength || el.maxlength || el.getAttribute('maxlength')` now. It seems jQuery should do the same.

Changed July 15, 2011 01:42PM UTC by jdalton comment:3

MSDN suggests maxLength is not supported on TEXTAREA's yet:

http://msdn.microsoft.com/en-us/library/ms534157(v=vs.85).aspx

IE9 is behaving more like other browsers by not automagically creating a property for unknown attributes.

Besides the prop access issue you will have the max length not enforced. I don't think it falls on to jQuery to create fallbacks for HTML5 support.

Changed July 15, 2011 02:44PM UTC by mathias comment:4

Replying to [comment:3 jdalton]:

MSDN suggests maxLength is not supported on TEXTAREA's yet: http://msdn.microsoft.com/en-us/library/ms534157(v=vs.85).aspx

FWIW, here’s the bug for that: https://connect.microsoft.com/IE/feedback/details/679494/respect-maxlength-for-textarea-elements

IE9 is behaving more like other browsers by not automagically creating a property for unknown attributes. Besides the prop access issue you will have the max length not enforced. I don't think it falls on to jQuery to create fallbacks for HTML5 support.

I agree, but since jQuery already maps .prop('maxlength') to .prop('maxLength') it might make sense to add a fallback to .getAttribute('maxlength') so getting the property still works.

Changed October 17, 2011 08:24PM UTC by timmywil comment:5

priority: undecidedlow
resolution: → wontfix
status: openclosed

Seems to me this is similar to $('input').prop('placeholder'). I don't think we should ever be falling back to getAttribute with properties.