How do I remove :selected
attribute and add new one?
You want something like
$('#mySelect option:selected').removeAttr('selected');
$('#mySelect option:nth-child(5)').attr('selected','selected');//select the one you want
btw, are you talking about a select list single (e.g. dropdown)?... or a select multiple? - you'll need to adjust accordingly if this is a multi-select.
I updated the nth child selector... when setting the selected attribute as square bracket notation [4] doesn't work in the selector.
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