Skip to main content

Bug Tracker

Side navigation

#10396 closed bug (duplicate)

Opened October 01, 2011 08:45PM UTC

Closed October 01, 2011 09:38PM UTC

Last modified October 02, 2011 02:29PM UTC

.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 );
}
Attachments (0)
Change History (3)

Changed October 01, 2011 09:38PM UTC by rwaldron comment:1

resolution: → duplicate
status: newclosed

Changed October 01, 2011 09:38PM UTC by rwaldron comment:2

Duplicate of #9427.

Changed October 02, 2011 02:29PM UTC by oraz comment:3

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.