JSFiddle - React, Tailwind, and code Playground
by Taleeb Anwar
HTML
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<input type='text' id='txtFilter' placeholder='filter' />
<br />
<select multiple>
<option>Google</option>
<option>Microsoft</option>
<option>Stack Overflow</option>
<option>PVC</option>
<option>KPMG</option>
<option>Some company</option>
<option>Some other new company</option>
<option>Alphabet</option>
</select>
JavaScript
function stringStartsWith(string, prefix) {
return string.slice(0, prefix.length) == prefix;
}
$('#txtFilter').keyup(function() {
var filter = $(this).val();
$('select option').each(function() {
if (stringStartsWith($(this).val(), filter)) {
$(this).show();
}
else{
$(this).hide();
}
});
});