Please take a look at the example: http://jsfiddle.net/HHDpK/1/
As you see the difference between two choosers is only the line
$("#chooser-1 .y").removeAttr("selected");
But as a result their states are different (especially in Chrome). Am I missing anything, or it is a bug?
Looks like internal bug of jQuery with attributes.
Note that in older versions, before .prop()
was introduced in 1.6 version, it works as expected.
In the newer versions, just use .prop()
to deal with such properties of elements:
$("#chooser-1 .x").prop("selected", "selected");
$("#chooser-1 .y").removeProp("selected");
jsFiddle update.
More than that - using .removeProp("selected")
on the element selected previously with prop()
will cause the original selection to return instead of having nothing selected - ideal behavior.
I found the above answer failed as well, I had to set the prop to false to get the selected items to not be.
$("#chooser-1 .x").prop("selected", false);
removeProp cause undesired effects such as not being able to re-select the options again.
I use jquery 1.6.2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With