#10502 closed bug (invalid)
attr should return an empty string, not undefined per DOM spec.
Reported by: | 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
- still falsey, so you can still
if (attr)
, - follows the spec, and
- is the previous behavior.
Change History (3)
comment:1 follow-up: 2 Changed 12 years ago by
Component: | unfiled → attributes |
---|---|
Priority: | undecided → low |
Resolution: | → invalid |
Status: | new → closed |
comment:2 Changed 12 years ago by
Replying to 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.
comment:3 Changed 12 years ago by
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.