Target: From a select dropdown menu, if someone selects an option, disable/remove/hide the rest of the options on that dropdown menu.
Here is the dropdown menu. If someone selects "1", the rest of options (2,3,4) will be removed/disabled/hide:
<div class="abc">
<div class="xyz">
<select name="pqr" class="selectDropdown">
<option value='1'>1</option>
<option value='2'>2</option>
<option value='3'>3</option>
<option value='4'>4</option>
</select>
</div>
</div>
Here is the JavaScript I tried to use:
$('.selectDropdown').on('change', function(e) {
$(this).closest('.abc').children('.xyz').children('option:not(:selected)').prop('disabled', true);
});
I know, the JavaScript is faulty here. Where did I make the mistake?