This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.
Specification: http://www.whatwg.org/specs/web-apps/current-work/multipage/the-button-element.html Multipage: http://www.whatwg.org/C#the-select-element Complete: http://www.whatwg.org/c#the-select-element Referrer: http://www.whatwg.org/specs/web-apps/current-work/multipage/ Comment: HTMLSelectElement remove should take (HTMLElement or long) Posted from: 2620:0:1003:1017:2e41:38ff:fea6:f2aa User agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.3 Safari/537.36
The IDL in the spec says void remove(long index); but it needs to be void remove((HTMLElement or long) child); and of course the prose needs to be updated too. Tested in Chrome, Firefox and IE. They all pass the following: test('remove', function() { var select = document.createElement('select'); var a = document.createElement('option'); a.text = 'a'; select.appendChild(a); var b = document.createElement('option'); b.text = 'b'; select.appendChild(b); var c = document.createElement('option'); c.text = 'c'; select.appendChild(c); select.remove(a); assert.equal(select.firstChild, b); assert.equal(select.lastChild, c); select.remove(1); assert.equal(select.firstChild, b); assert.equal(select.lastChild, b); });
Does this apply to HTMLOptionsCollection also? Basically remove() is like add()'s second argument in both cases?
(In reply to Ian 'Hixie' Hickson from comment #2) > Does this apply to HTMLOptionsCollection also? Blink/WebKit allows an element in HTMLOptionsCollection remove Gecko and Trident do not and they only accept an index
I guess I'll go with consistency and hope that Firefox/IE follow suit.
(In reply to Ian 'Hixie' Hickson from comment #4) > I guess I'll go with consistency and hope that Firefox/IE follow suit. Makes sense to me
Actually I can't get select.remove() to work with an element. All objects seem to be treated as zero, in all browsers I tested. http://software.hixie.ch/utilities/js/live-dom-viewer/saved/2826 http://software.hixie.ch/utilities/js/live-dom-viewer/saved/2828 http://software.hixie.ch/utilities/js/live-dom-viewer/saved/2825 http://software.hixie.ch/utilities/js/live-dom-viewer/saved/2827 It works in your test because you try to remove the first entry, which is treated like zero. I've updated the spec to convert object arguments to zero. Please reopen the bug if I made a mistake here.
test from comment 1, for posterity: http://software.hixie.ch/utilities/js/live-dom-viewer/saved/2829
Checked in as WHATWG revision r8481. Check-in comment: Turns out select.remove() and select.options.remove() convert object arguments to zero. http://html5.org/tools/web-apps-tracker?from=8480&to=8481
You are right. Sorry for the misleading test.
Uh, why did this need a spec change? IDL will coerce an object to the 0 value of "long" unless it has a valueOf that says otherwise. That's because ToNumber() will return NaN, and converting NaN to a long gives 0...
In particular, I expect the new spec behavior is not compatible with UA behavior if someone does: remove({ valueOf: function() { return 1; } });
BZ is right. I'm sorry for causing all this mess. The old spec was correct and WebKit/Blink behavior was following the spec except that our IDL was misleading.
Lets revert back to the old behavior because that is what Blink, Gecko, Trident does.
Ah, yeah, I misunderstood the ToPrimitive logic in the JS spec. Thanks bz!
Checked in as WHATWG revision r8497. Check-in comment: Revert r8481 since I misunderstood how ToNumber works on objects. http://html5.org/tools/web-apps-tracker?from=8496&to=8497