Bug Tracker

Ticket #10502 (closed bug: invalid)

Opened 3 years ago

Last modified 3 years ago

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:
Blocking: Blocked by:

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.

Change History

comment:1 follow-up: ↓ 2 Changed 3 years ago by timmywil

  • Priority changed from undecided to low
  • Resolution set to invalid
  • Status changed from new to closed
  • Component changed from unfiled to attributes

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

comment:2 in reply to: ↑ 1 Changed 3 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 3 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.