Bug Tracker

Modify

Ticket #10396 (closed bug: duplicate)

Opened 20 months ago

Last modified 20 months ago

.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:

  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

comment:1 Changed 20 months ago by rwaldron

  • Status changed from new to closed
  • Resolution set to duplicate

comment:2 Changed 20 months ago by rwaldron

Duplicate of #9427.

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.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.