Bug Tracker

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#10502 closed bug (invalid)

attr should return an empty string, not undefined per DOM spec.

Reported by: rpflorence@… Owned by:
Priority: low Milestone: None
Component: attributes Version: 1.6.4
Keywords: Cc:
Blocked by: Blocking:


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.

Change History (3)

comment:1 Changed 12 years ago by Timmy Willison

Component: unfiledattributes
Priority: undecidedlow
Resolution: invalid
Status: newclosed

We are following spec exactly now actually. There is no title attribute on that element.

comment:2 in reply to:  1 Changed 12 years ago by rpflorence

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 dmethvin

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.

Note: See TracTickets for help on using tickets.