When I use alert($("select").find("option:selected").val());
on a select that has no option selected, jQuery alerts the value of the first element within the select.
Why is that, and how do I get my expected return value of ''
or even undefined
?
Link to fiddle: jsfiddle
alert($(".select").find("option:selected").val());
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select class="select">
<option value="1">Test 1</option>
<option value="2">Test 2</option>
<option value="3">Test 3</option>
<option value="4">Test 4</option>
<option value="5">Test 5</option>
</select>