JSFiddle - React, Tailwind, and code Playground

by Nathaniel Anderson

HTML

<button id="button">Click</button>
<select id="name" >
    <option value="">explicit empty string</option>
    <option value="1" selected>Click button to change to explicit empty string</option>
</select>
<select id="name3" >
    <option value="1" selected>Click button to change to explicit empty string</option>
    <option value="">explicit empty string in non-first position</option>
    <option value="2" >Click button to change to explicit empty string</option>
</select>


<select id="name2" >
    <option >omit value attribute -- this won't get set with val(''); it can't; it doesn't have a value, not even empty string</option>
    <option value="1" selected>Click button to change to a null/undefined value; appears "blank"</option>
</select>

JavaScript

$('#button').click(function(){
    $('#name').val('')
    $('#name2').val('')
    $('#name3').val('')
});