Bug Tracker

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

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

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:

  1. when we pass object like {someAttr: undefined} as only argument: http://jsfiddle.net/oraz/aBnb4/
  2. 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 (3)

comment:1 Changed 8 years ago by Rick Waldron

Resolution: duplicate
Status: newclosed

comment:2 Changed 8 years ago by Rick Waldron

Duplicate of #9427.

comment:3 Changed 8 years 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.

Note: See TracTickets for help on using tickets.