I have
<select id="baba"> <option>select something</option> <option value="1">something 1</option> <option value=2">something 2</option> </select>
Using jQuery, what would be the easiest (less to write) way to reset the select
so the first option is selected?
To remove the options of an HTML element of select , you can utilize the remove() method: function removeOptions(selectElement) { var i, L = selectElement.
To reset a dropdown in JavaScript, set selectedIndex to 0 .
With jQuery, you can use the . remove() method to takes elements out of the DOM. To get the selected item from a dropdown, you can use the :selected property and call remove() on the matched element.
Try this. This will work. $('#baba').prop('selectedIndex',0);
Check here http://jsfiddle.net/bibin_v/R4s3U/
In your case (and in most use cases I have seen), all you need is:
$("#baba").val("");
Demo.
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