Skip to main content

Bug Tracker

Side navigation

#10870 closed bug (fixed)

Opened November 23, 2011 09:26AM UTC

Closed March 05, 2012 05:54PM UTC

Incorrect behaviour of $.removeAttr("selected")

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

Calling $.removeAttr("selected") on the option that doesn't have "selected" attribute, changes the selection.


Based on

Attachments (0)
Change History (10)

Changed November 23, 2011 10:30AM UTC by addyosmani comment:1

component: unfiledattributes
priority: undecidedlow
resolution: → worksforme
status: newclosed

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

Changed November 23, 2011 10:35AM UTC by comment:2

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.

Changed November 23, 2011 02:56PM UTC by timmywil comment:3

resolution: worksforme
status: closedreopened

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.

Changed November 23, 2011 02:56PM UTC by timmywil comment:4

milestone: None1.7.2
owner: → timmywil
status: reopenedassigned

Changed November 23, 2011 02:56PM UTC by timmywil comment:5

Changed November 25, 2011 03:54AM UTC by timmywil comment:6

#10883 is a duplicate of this ticket.

Changed January 09, 2012 03:27PM UTC by timmywil comment:7

#11142 is a duplicate of this ticket.

Changed January 20, 2012 03:28PM UTC by timmywil comment:8

priority: lowhigh

Changed February 09, 2012 05:55AM UTC by comment:9

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

Changed March 05, 2012 05:54PM UTC by timmywil comment:10

resolution: → fixed
status: assignedclosed

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

Changeset: d3320462df1253196e61b2daadc3cdfe1b4c3771