Bug Tracker

Opened 10 years ago

Closed 10 years ago

#13189 closed bug (notabug)

Inconsistency with .attr() accessor and mutator for missing attributes

Reported by: [email protected] Owned by:
Priority: low Milestone: None
Component: attributes Version: 1.8.2
Keywords: Cc:
Blocked by: Blocking:


When .attr(attrName) is called on a selection that does not have an attrName attribute, undefined is returned.

When .attr(attrName, undefined) is called on a selection, the attrName attribute is not removed. Instead .attr(attrName, null) must be called to remove the attrName attribute from the selection of elements.

For consistency, I see two options being available:

Option 1

<div data-example="example"></div>
  $('div').attr('data-example', undefined);

should result in:


Option 2


should result in:



Change History (1)

comment:1 Changed 10 years ago by timmywil

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

.removeAttr should be used to remove attributes. Setting to null or undefined has no affect (by spec) on some attributes.

Note: See TracTickets for help on using tickets.