Ticket #10396 (closed bug: duplicate)
.attr('name', undefined) returns attr value instead of current set
| Reported by: | oraz | Owned by: | |
|---|---|---|---|
| Priority: | undecided | Milestone: | None |
| Component: | unfiled | Version: | 1.6.4 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
.attr() returns attribute value instead of current node set if the second argument is undefined. Code to reproduce: http://jsfiddle.net/oraz/zDNCb/
In the following examples .attr() returns current node set:
- when we pass object like {someAttr: undefined} as only argument: http://jsfiddle.net/oraz/aBnb4/
- when we pass null as the second argument: http://jsfiddle.net/oraz/3frQB/
Environment:
- jQuery 1.6.4
- jQuery 1.6.2
- Firefox 7
- Google Chrome 14
- IE 8
Possible fix at line 1956:
attr: function( name, value ) {
if(arguments.length == 2 && value === undefined) {
value = null;
}
return jQuery.access( this, name, value, true, jQuery.attr );
}
Change History
comment:1 Changed 20 months ago by rwaldron
- Status changed from new to closed
- Resolution set to duplicate
comment:3 Changed 20 months ago by oraz
Why the issue was closed?
What's the difference between the following examples?
$('body').attr({someAttr: undefined}).each(function() { alert('Hello'); });
$('body').attr('someAttr', undefined).each(function() { alert('Hello'); });
As for me, these examples are identical, but the first works fine and the second one doesn't work. It means that .attr() (.css(), data(), etc...) method returns different result even if I pass actually the same attr name and value.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
