This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 20720 - Define HTMLSelectElement.remove() (without argument) to do the same as ChildNode.remove()
Summary: Define HTMLSelectElement.remove() (without argument) to do the same as ChildN...
Status: RESOLVED FIXED
Alias: None
Product: WHATWG
Classification: Unclassified
Component: HTML (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: Unsorted
Assignee: Ian 'Hixie' Hickson
QA Contact: contributor
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 23398
  Show dependency treegraph
 
Reported: 2013-01-21 05:55 UTC by Ilia
Modified: 2013-09-30 18:12 UTC (History)
9 users (show)

See Also:


Attachments

Description Ilia 2013-01-21 05:55:53 UTC
The remove() method from Interface Element [ http://www.w3.org/TR/dom/#dom-childnode-remove ] is overwritten with The remove() method from Interface HTMLSelectElement [ http://www.w3.org/TR/REC-DOM-Level-1/level-one-html.html#ID-33404570 ] for the select nodes.
Today, I have to use something like this:
window.HTMLSelectElement && function(HTMLSelectElementPrototype)
{
    var removeOption = HTMLSelectElementPrototype.remove;

    HTMLSelectElementPrototype.remove = function()
    {
        if (arguments[0] >= 0) removeOption.call(this, arguments[0]);
        else this.parentNode && this.parentNode.removeChild(this);
    };
}(window.HTMLSelectElement.prototype);

It would be better to change HTMLSelectElement Interface so that without arguments it used remove method like Element Interface.
Comment 1 Ms2ger 2013-01-21 07:48:12 UTC
Hrm, <http://www.whatwg.org/html/#the-select-element> has

  void remove(long index);

so I guess we could make it work with our

  void remove();

but I'm not sure if WebIDL supports that... Cameron?
Comment 2 Boris Zbarsky 2013-01-21 13:39:56 UTC
One option would be for HTMLSelectElement to define overloads with and without and index and explicitly say that the no-argument overload does the same thing as the canonical Element.prototype.remove.

That's how an ES implementation would have to implement it, and I think specifying it that way is simplest.  It also happens to be simple to implement, at least in Gecko.  ;)
Comment 3 Anne 2013-01-21 13:59:54 UTC
Ian, care to make that change in HTML?
Comment 4 Cameron McCormack 2013-01-21 22:47:00 UTC
I agree with Boris; that's the simplest solution.  (I think overloading operations with those from an inherited interface could be confusing for the reader.)
Comment 5 Ilia 2013-01-22 19:24:12 UTC
Hi guys! I was wondering what is the difference between selectNode.remove(optionIndex) and selectNode[optionIndex].remove()? Do we need 2 different methods for doing extactly the same thing?
Maybe this situation occurred because the method "remove" from HTMLSelectElement  interface was so replaceable and too few people really enjoyed them? Maybe it is time for him to retire?
Comment 6 Ms2ger 2013-01-22 19:26:09 UTC
HTMLSelectElement.remove(i) removes the i'th option element from the this element; ChildNode.remove() removes the this object from its parent, if any.
Comment 7 Ilia 2013-01-22 19:40:41 UTC
HTMLSelectElement.remove(i) - removes the i'th option
HTMLSelectElement[i].remove() - removes the i'th option

it is 100% replaceable, am I right?
Comment 8 Ms2ger 2013-01-22 19:41:54 UTC
Sure. We can't remove select.remove(i), though, because pages use that.
Comment 9 Ilia 2013-01-22 19:47:02 UTC
Is a pity, it would be a little easier.
Comment 10 Ian 'Hixie' Hickson 2013-01-24 23:24:08 UTC
Having remove() remove the element from its parent and remove(i) remove a child from the element is very confusing. Can't we rename ChildNode.remove()?
Comment 11 Syoichi Tsuyuhara 2013-01-25 03:54:34 UTC
WebKit already implemented ChildNode.remove() by Erik Arvidsson, and Google Chrome 24(stable) has it now.
http://wkrev.com/129400
http://wkb.ug/73885

But I guess that web developers aren't so using ChildNode.remove()...
Comment 12 Ms2ger 2013-01-25 13:13:49 UTC
Do you have a better name?
Comment 13 Ian 'Hixie' Hickson 2013-01-25 22:36:12 UTC
unparent()
removeFromParent()
detach()
Comment 14 Ian 'Hixie' Hickson 2013-03-20 18:56:01 UTC
I'm kicking this over to DOM, because remove() on HTMLSelectElement is ancient and having both do basically opposite things is going to be very confusing.
Comment 15 Anne 2013-03-21 14:46:10 UTC
It does not seem that confusing to me that on one element there is an overloaded version that removes a child via an index which is largely a legacy API anyway.
Comment 16 Ian 'Hixie' Hickson 2013-05-04 06:41:24 UTC
How is a method that does two diametrically opposite things not confusing??
Comment 17 Anne 2013-09-13 07:57:51 UTC
So I don't think we're going to change. Hmm.
Comment 18 Ms2ger 2013-09-23 19:24:32 UTC
Firefox 23 ships this.
Comment 19 contributor 2013-09-23 19:31:43 UTC
Checked in as WHATWG revision r8192.
Check-in comment: remove() is also defined on an ancestor interface, so overload it here on <select>.
http://html5.org/tools/web-apps-tracker?from=8191&to=8192