Bug Tracker


Ticket #10870 (closed bug: fixed)

Opened 2 years ago

Last modified 2 years ago

Incorrect behaviour of $.removeAttr("selected")

Reported by: smartmaxim@… Owned by: timmywil
Priority: high Milestone: 1.7.2
Component: attributes Version: 1.7
Keywords: Cc:
Blocking: Blocked by:


Calling $.removeAttr("selected") on the option that doesn't have "selected" attribute, changes the selection. Example:  http://jsfiddle.net/HHDpK/1/

Based on  http://stackoverflow.com/questions/8226702/jquery-removeattrselected-changes-selected-option

Change History

comment:1 Changed 2 years ago by addyosmani

  • Priority changed from undecided to low
  • Resolution set to worksforme
  • Status changed from new to closed
  • Component changed from unfiled to attributes

Thanks for submitting a ticket to the jQuery bug tracker. Please note that switching over to using .prop() for such cases (and .removeProp()) or the property removal should solve the problem you're running into. See here (jsFiddle from the answer on your SO post):  http://jsfiddle.net/HHDpK/3/.

comment:2 Changed 2 years ago by smartmaxim@…

Do I understand you correctly that $.removeAttr() is not backward compatible since 1.6? Sure I'm going to use $.prop() in a new code, but there is plenty already written.

comment:3 Changed 2 years ago by timmywil

  • Status changed from closed to reopened
  • Resolution worksforme deleted

Do NOT remove native properties with .removeProp. They cannot be recreated. Instead, we recommend:

$elems.prop('selected', false);
$elems.prop('selected', true);

Anyway, with the boolHook, this should be working. In removeAttr, we are setting attributes to empty string before removal. Unfortunately, the mere presence of a boolean attribute indicates true for the property and sets all other options' selected properties to false, and then removes it.

comment:4 Changed 2 years ago by timmywil

  • Owner set to timmywil
  • Status changed from reopened to assigned
  • Milestone changed from None to 1.7.2

comment:6 Changed 2 years ago by timmywil

#10883 is a duplicate of this ticket.

comment:7 Changed 2 years ago by timmywil

#11142 is a duplicate of this ticket.

comment:8 Changed 2 years ago by timmywil

  • Priority changed from low to high

comment:9 Changed 2 years ago by liveever@…

Just check : It caused by #9699 (setting first, then removal) .

comment:10 Changed 2 years ago by timmywil

  • Status changed from assigned to closed
  • Resolution set to fixed

Do not set boolean attributes to empty string on removal. Fixes #10870. +0 bytes compressed

Changeset: d3320462df1253196e61b2daadc3cdfe1b4c3771

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.


Add a comment

Modify Ticket

as closed

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

Note: See TracTickets for help on using tickets.