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 4048690
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:50:57+00:00 2026-05-20T13:50:57+00:00

The code is here: http://jsfiddle.net/jf7t2/1/ Please run it on the latest versions of all

  • 0

The code is here:

http://jsfiddle.net/jf7t2/1/

Please run it on the latest versions of all browsers, and see for yourself. When the button is clicked, on:

  1. on Chrome (and Safari of course) it just doesn’t select anything, instead creates some ghostly empty option
  2. on Firefox and Opera, it works the way I expect and want it to work, de-selects all options
  3. on Internet Explorer, it does nothing

So, which one is the expected behaviour?

  • 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-05-20T13:50:57+00:00Added an answer on May 20, 2026 at 1:50 pm

    If you look at the jQuery 1.5.1 source code line 1970 you’ll see this:

    // Treat null/undefined as ""; convert numbers to string
    if ( val == null ) {
        val = "";
    

    So the expected behavior is the same as if you gave the empty string as argument.

    If you continue to line 1984 you’ll see this:

    } else if ( jQuery.nodeName( this, "select" ) ) {
      var values = jQuery.makeArray(val);
    
      jQuery( "option", this ).each(function() {
        this.selected = jQuery.inArray( jQuery(this).val(), values ) >= 0;
      });
      if ( !values.length ) {
       this.selectedIndex = -1;
      }
    

    So the expected behaviour is:

    1. if there is an option with an empty string value, choose that.
    2. if not set selectedIndex = -1

    From here on it is up to the browser to determine what to do if selectedIndex is set to -1

    Looking at the msdn library it says:

    The selectedIndex property returns -1
    if a select object does not contain
    any selected items. Setting the
    selectedIndex property clears any
    existing selected items.

    So in ie the expected behavior seems to be that it will de-select all options

    The same goes for the MDC documentation and thus firefox, where theya re very explicit about it

    Returns the index of the currently
    selected item. You may select an item
    by assigning its index to this
    property. By assigning -1 to this
    property, all items will be
    deselected.

    It seems webkit based browsers have a different take on things.

    If you google “webkit selectedIndex” you will see quite a few bug report regarding the select tag, so maybe it’s just funky 😉

    Come to think of it, this is a bug in jQuery since it is a library that should be able to behave the same across browsers – it should be reported 😉

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

Sidebar

Related Questions

Please see the code here: http://jsfiddle.net/wQpTu/1/ For some reason, it always returns false on
I'm trying to create a header menu. Please see my code here: http://jsfiddle.net/kc2cc/ .
Please find the code at http://jsfiddle.net/wlogeshwaran/NGL8P/4/ Here i want to make the 'hi' ,
You can see the code live here: http://jsfiddle.net/z3xV3/50/ My HTML: <div id=slider></div> <input id=sliderValue
All of this is code is here: http://jsfiddle.net/yrgK8/ I have a news section which
I have this code here http://jsfiddle.net/RzBeM/65/ you will see two input fields called quantity.
my code here http://jsfiddle.net/GKZRU/14/ all js working properly, and add/remove css classes(checking this in
I have a working version of my code here: http://jsfiddle.net/5Hqs3/24/ As you can see,
Please check out my code here http://jsfiddle.net/bYDPr/20/ So I have some HTML textarea elements
jquery how to addClass to all the ul.menu li:first.selection ? demo code here: http://jsfiddle.net/NkbDY/

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.