In this simple violin, I tested to select a parameter from a select jQuery element that works once ... But if I want to clear the preliminary selection and set it again several times (use both buttons a second time), it does not change anymore. .. I tried it in firefox and chrome.
Why is this? Until they found a solution :(
HTML:
<select>
<option value="1">Test 1</option>
<option value="2">Test 2</option>
<option value="3">Test 3</option>
</select>
<button id="select2">preselect 2nd</button>
<button id="selectNone">preselect none</button>
JavaScript:
$("#select2").click(function() {
$("select option:nth-of-type(2)").attr("selected", true);
});
$("#selectNone").click(function() {
$("option").attr("selected", false);
});
Thanks in advance! Severin
source
share