Side navigation
#13189 closed bug (notabug)
Opened January 10, 2013 04:01PM UTC
Closed January 21, 2013 07:24PM UTC
Inconsistency with .attr() accessor and mutator for missing attributes
Reported by: | zzzzBov@gmail.com | Owned by: | |
---|---|---|---|
Priority: | low | Milestone: | None |
Component: | attributes | Version: | 1.8.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
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> <script> $('div').attr('data-example', undefined); </script>
should result in:
<div></div>
Option 2
<div></div> <script> console.log($('div').attr('data-example')); </script>
should result in:
null
Attachments (0)
Change History (1)
Changed January 21, 2013 07:24PM UTC by comment:1
component: | unfiled → attributes |
---|---|
priority: | undecided → low |
resolution: | → notabug |
status: | new → closed |
.removeAttr
should be used to remove attributes. Setting tonull
orundefined
has no affect (by spec) on some attributes.