Bug Tracker

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#13474 closed bug (notabug)

Boolean attribute (such as 'selected') cannot be set back after reset with Firefox

Reported by: Michel (R) Owned by: Michel (R)
Priority: undecided Milestone: None
Component: attributes Version: 1.9.1
Keywords: Cc:
Blocked by: Blocking:


Firefox version: 18.0.2

If I use jQuery to set the 'selected' attribute on an option element, it works.

However if I reset this attribute, then the set method doesn't work anymore.

It works normally under IE (8).

The problem is in this part:

  removeAttr: function( elem, value ) {
    } else {
      elem[ propName ] = false; // <<====

The set methods is something like:

set: function( elem, value, name ) {
   elem.setAttribute( !getSetAttribute && jQuery.propFix[ name ] || name, name );

Which in our case does:

   elem.setAttribute(name, name)

If elem[name] = false was called before, it doesn't work anymore under Firefox.

Apparently, the following line seems to fix the problem under this version of Firefox and IE8 but I cannot test with other browsers nor did I try other possibilities:

   elem[name] = name;

Change History (4)

comment:1 Changed 9 years ago by gibson042

Owner: set to Michel (R)
Status: newpending

Thanks for taking the time to contribute to the jQuery project! Treatment of boolean attributes has changed recently, and .attr and .prop can interact in non-obvious ways with respect to them, so please provide a complete reduced test case on jsFiddle to help us assess your ticket.

comment:2 Changed 9 years ago by michelgre


Yes I wanted to prepare a test case but it was kind of late (after midnight my time). Thank you for the fiddle link.

Here it is:


When loaded, both options should be selected. On my Firefox 18.0.2, only the first one is.

Last edited 9 years ago by michelgre (previous) (diff)

comment:3 Changed 9 years ago by gibson042

Component: unfiledattributes
Resolution: notabug
Status: pendingclosed

Please use .prop to update the dynamic state of elements: http://jsfiddle.net/3UwC8/2/

As of version 1.9, we no longer guarantee any user-visible effects of adding or removing boolean attributes, so they may vary between browsers. Also note that the migrate plugin both restores and warns about the old behavior: http://jsfiddle.net/3UwC8/3/

comment:4 Changed 9 years ago by michelgre

Thanks, I see.

This code was actually part of a 3rd party jQuery UI widget, so this means that I should warn the author that his plugin should be fixed.

Thanks for the advices!

Note: See TracTickets for help on using tickets.