It is an easy task to hide the option in a select.
jQuery("#bbb").hide();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select id="mySelect">
<option id="aaa">A</option>
<option id="bbb">B</option>
<option id="ccc">C</option>
</select>
But how does it work in Selectmenu UI ? I can only remove options, but hiding them seems to be impossible.
For example I try to hide the option 'RAL Sonderfarbe' on the select Farbe:
Attempt (in dev console):
var $el = jQuery('option:contains("RAL Sonderfarbe")');
$el.hide();
$hausfux_laenge_dropdown.find('select').selectmenu('refresh');
But it does not work.
I found a workaround, but if selectmenu('refresh');
is called, then the option appears again...
$('#mySelect').selectmenu();
var mySelectOpened = false;
$('#mySelect').selectmenu({
open: function(event, ui) {
if (mySelectOpened == false) {
mySelectOpened = true;
var $el1 = $('#mySelect option:contains("B")');
var $el2 = $('li:contains("B")');
$el1.hide();
$el2.hide();
}
}
});
$("#refresh").click(function() {
$('#mySelect').selectmenu('refresh');
});
<link href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<select id="mySelect">
<option id="aaa">A</option>
<option id="bbb">B</option>
<option id="ccc">C</option>
</select>
<button id="refresh">Refresh Selectmenu UI</button>