The code is here:
Please run it on the latest versions of all browsers, and see for yourself. When the button is clicked, on:
- on Chrome (and Safari of course) it just doesn’t select anything, instead creates some ghostly empty option
- on Firefox and Opera, it works the way I expect and want it to work, de-selects all options
- on Internet Explorer, it does nothing
So, which one is the expected behaviour?
If you look at the jQuery 1.5.1 source code line 1970 you’ll see this:
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:
So the expected behaviour is:
optionwith an empty string value, choose that.selectedIndex = -1From here on it is up to the browser to determine what to do if
selectedIndexis set to-1Looking at the msdn library it says:
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
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 😉