I have 'some text' in a list and if this matches then I am showing select options in .input-1 dropdown, but what I cannot get to work is the opposite where it does not match the string. In this case, I want to hide the select options.
The first part of the code works, but second else if fails
jQuery(document).ready( function() {
$('.input-1 option').each(function() {
var ourOption = $(this).text().toLowerCase(); // convert text to Lowercase
var str = "Some Text";
var res = str.toLowerCase();
if (ourOption.match(res)) {
$(this).css('display', 'block');
}
else if (!ourOption.match(res)) {
$(this).css('display', 'none');
}
})
});
The current result is that all options are hidden regardless of the matched text so I'm guessing there is an error in my else if or the syntax for no match is incorrect.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…