I am wanting to hide a span/div when a select option is selected.
Ok, so there are a bazillion of these already listed here at SO.
But none that I can find seem to address the issue of only having two <options>
and clicking on the first <option>
cause the entire span/div to hide.
Example of what I have:
<span id="showPrivacy" style="cursor:pointer;">
show privacy
</span>
<span id="displayPrivacy" style="display:none">
<select name="privacy" id="privacy">
<option value="members">members</option>
<option value="friends">friends only</option>
</select>
</span>
and
$("#showPrivacy").click(function(){
$("#displayPrivacy").toggle();
});
$('#privacy').change(function() {
if($('#privacy').val() == 'members') {
$('#displayPrivacy').hide();
} else if($('#privacy').val() == 'friends') {
$('#displayPrivacy').hide();
}
else {
console.log('value: unknown');
}
});
If you click on the first option, the members
option, the change()
does not fire because the value has not actually changed.
So, my question here is simply, how do I get the span/div with id displayPrivacy
to hide when the user clicks members
, even if the members
is the default option value?
I do not want to add a null <option>
at the top of the options list to solve this situation.