Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8122933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:59:38+00:00 2026-06-06T05:59:38+00:00

Note: this question has nothing to do with Knockout.js, but it’s about the selectedOptions

  • 0

Note: this question has nothing to do with Knockout.js, but it’s about the selectedOptions attribute of <select> elements instead. This is the reference:

http://www.whatwg.org/specs/web-apps/current-work/multipage/the-button-element.html#dom-select-selectedoptions

I think it’s a nice feature for Javascript developers. The support is quite limited, but it’s growing anyway. Chrome, Opera and Safari should already support it.

The problem is that I can’t figure out how it works. The behaviour should be quite straightforward, yielding a live collection of the selected options, but it turns out to be not the case. You’d imagine that selectedOptions changes everytime the user selects an option, right? Wrong. I’ve prepared a test case:

http://jsfiddle.net/f39cC/5/

In this example, Opera 11.64 always returns the first value selected, no matter what you do after, while Chrome 21 dev and 19 stable have an odd behaviour. Do the following steps:

  1. Select ‘One’. In both output and console you get “One”, as expected.
  2. Select ‘Two’ too, using Ctrl. In console you get “One,Two”, in output it’s still “One”.
  3. Select ‘Three’ too. In console it’s “One,Two,Three”, in output it’s “One,Two”.
  4. Now select ‘Two’ only. In console you get “Two”, in output “Two,,” (notice the two commas).

However, if you comment out the console.log line, you always get the correct output. You can get the expected behaviour in both console and output if you swap the two instructions, or if you store the value in a separated string, as in this:

http://jsfiddle.net/f39cC/2/

So, am I missing something about selectedOptions? Is it too soon to rely on this property, that probably has a buggy implementation? Is console.log creating the issue in Chrome? Is there something I don’t know about HTMLCollections?

I don’t have Safari installed, can someone check its behaviour?

UPDATE 18/2/2013: I don’t know when things have changed, but both Chrome 24.0.1312.57 and Opera 12.14 seems to work fine now. Firefox 18.0.2 and Internet Explorer 10 still have to implement the property.

UPDATE 17/9/2013: Firefox 24 and IE 11 preview still have to support the property. This is an easy workaround for Firefox and IE8-11:

Object.defineProperty(HTMLSelectElement.prototype, "selectedOptions", {
    get: (function() {
        try {
            document.querySelector(":checked");
            return function() {
                return this.querySelectorAll(":checked");
            };
        } catch (e) {
            return function() {
                if (!this.multiple) {
                    return this.selectedIndex >= 0
                            ? [this.options[this.selectedIndex]] : [];
                }
                for (var i = 0, a = []; i < this.options.length; i++)
                    if (this.options[i].selected) a.push(this.options[i]);
                return a;
            };
        }
    })()
});

For IE8 it returns just an Array and not a NodeList, though.

UPDATE 28/5/2014: It looks like Firefox started implementing selectedOptions since r25.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T05:59:39+00:00Added an answer on June 6, 2026 at 5:59 am

    It seems that the problem is a bit deeper than a simple bug. The fact that both WebKit and Presto failed to support selectedOptions correctly gives us the hint that it depends on the fact that the property is supposed to be a HTMLCollection.

    Now, HTMLCollections have their live behaviour because they’re invalidated by the rendering engine when something happens to the DOM (the change of a class, the removal of a node and so on). But the selected property of an option does not trigger the invalidation of the collection, thus making it completely unreliable.

    I guess the problem here is to make a new way live collections are invalidated, and it may be not very simple since it may affect the whole way the DOM is interpreted and handled.

    At the present time, Chrome 21.0.1180.4 has the property removed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Note: This question uses jQuery but the question has nothing to do with jQuery
Note: This question has broadened in scope from previous revisions. I have tried to
Note: this question is related to this one , but two years is a
Note: This is similar to this question but it is not the same. I
(note that this question is not about CAS, it's about the May fail spuriously
NOTE : This has to do with how existing canvas elements are rendered when
Note this question was originally posted in 2009, before C++11 was ratified and before
Note: This question is related to an advice rather than an issue. I would
Please note this question related to performance only. Lets skip design guidelines, philosophy, compatibility,
Note: In this question I'm using the term autocomplete (or iterative search) to refer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.