1. ホーム
  2. jquery

[解決済み] [Solved] Best way to unselect a <select> in jQuery?

2022-04-04 17:44:54

Question

<select size="2">
<option selected="selected">Input your option</option>
<option>Input your option</option>
</select>

What is the best way, using jQuery, to elegantly unselect the option?

How to solved?

Use removeAttr ...

$("option:selected").removeAttr("selected");

Or Prop

$("option:selected").prop("selected", false)