Ticket #3917 (closed bug: wontfix)
input maxLength property/attribute is not consistent
| Reported by: | webbower | Owned by: | |
|---|---|---|---|
| Priority: | minor | Milestone: | 1.3.1 |
| Component: | core | Version: | 1.3 |
| Keywords: | attr input maxLength | Cc: | |
| Blocking: | Blocked by: |
Description
The example I found was trying to get the "maxlength" attribute from a text input element and if it was not set, the function returned "-1" instead of undefined like the documentation says. My Firebug helped me discover the actual result. I'm not sure if the bug exists when trying to get other attributes or if it also returns "-1" for other attributes that aren't set.
Mac OS X 10.5.6 Firefox 3.0.5 Firebug 1.2.1
Attachments
Change History
Changed 4 years ago by dmethvin
-
attachment
test-3917.html
added
comment:1 follow-up: ↓ 2 Changed 4 years ago by dmethvin
- Keywords attr input maxLength added
- Summary changed from $(el).attr(name) does not return undefined if attritbute is not set in some cases to input maxLength property/attribute is not consistent
This isn't consistent across browsers, or even across property vs. attribute. However, the behavior has not changed since 1.2.6. I've attached a test case. In FF3, the maxLength property is -1 and the maxLength attribute is null. In Ie the property is 2147483647 and the attribute is null. jQuery returns the property value in preference to the attribute, and the property value is defined.
comment:3 Changed 4 years ago by brandon
- Status changed from new to closed
- Resolution set to wontfix
Unfortunately we can't have it both ways. IE immediately converts the attribute to a property/expando and using the setAttribute/removeAttribute/getAttribute apis no long work.
Not sure we can normalize this without a large impact on performance.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

maxLength property vs. attribute