A more succinct way to do this would be to put a common class on all the div
elements you want to toggle so that you can easily hide them on change
. In addition, add another class to them which matches the value
of the option
of they should be displayed when selected. From there you can easily build a selector to hide/show the content. Try this:
var $privileges = jQuery('#privileges');
$privileges.on('change', e => {
$('.content').hide().filter('.' + e.target.value).show();
});
.content {
display: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div>
<label>Privileges:</label>
<select name="privileges" id="privileges">
<option value="all">All</option>
<option value="custom">Custom</option>
<option value="test1">test1</option>
<option value="test2">tst2</option>
</select>
</div>
<div class="content custom">resources</div>
<div class="content test1">test1</div>
<div class="content test2">test2</div>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…