For some reason I'm having trouble selecting an existing blank value in a dropdown with jQuery. The blank option exists, but setting it via $('#studyList option[value=""]').prop('selected', 'selected');
does not work (nor does .prop('selected', true)
). Am I doing something wrong?
$('#studyList').append(
$('<option value="155" selected="selected">Study 1</option>'));
$('#studyList').append(
$('<option value="157">Study 2</option>'));
$('#studyList').prepend("<option value='' ></option>");
function clear() {
$('#studyList option[value=""]').prop('selected', 'selected');
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="studyList"></select>
<button id="clear" onclick="clear();" value="Clear">Clear</button>