Side navigation
#10502 closed bug (invalid)
Opened October 14, 2011 11:31PM UTC
Closed October 17, 2011 08:31PM UTC
Last modified October 19, 2011 03:14AM UTC
attr should return an empty string, not undefined per DOM spec.
| Reported by: | rpflorence@gmail.com | Owned by: | |
|---|---|---|---|
| Priority: | low | Milestone: | None |
| Component: | attributes | Version: | 1.6.4 |
| Keywords: | Cc: | ||
| Blocked by: | Blocking: |
Description
Incorrect 1.6 behavior: http://jsfiddle.net/rpflorence/PzRya/
Correct 1.5 behavior: http://jsfiddle.net/rpflorence/PzRya/1/
Spec: http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-666EE0F9
Returning an empty string is
1. still falsey, so you can still if (attr),
2. follows the spec, and
3. is the previous behavior.
Attachments (0)
Change History (3)
Changed October 17, 2011 08:31PM UTC by comment:1
| component: | unfiled → attributes |
|---|---|
| priority: | undecided → low |
| resolution: | → invalid |
| status: | new → closed |
Changed October 17, 2011 10:08PM UTC by comment:2
Replying to [comment:1 timmywil]:
We are following spec exactly now actually. There is no title attribute on that element.
Actually, now that I read the spec closer, it's impossible to "follow it exactly" because it isn't clear for this use case, where the attribute doesn't exist.
From the spec:
Return Value DOMString
>
The Attr value as a string, or the empty string if that attribute does not have a specified or default value."
I can respect the change to mimic the browsers' behavior, but claiming spec compliance isn't a valid reason for this API change. Returning an empty string is, in my opinion, more useful.
Changed October 19, 2011 03:14AM UTC by comment:3
To get an empty string you can use the property, available through .prop('title'). There is no title attribute in the markup so the browser is justifiably returning null for the .getAttribute('title') method call and therefore we are returning undefined.
We are following spec exactly now actually. There is no title attribute on that element.