Alright, so I want to show two divs when selecting on of the options in my selector.
This is what I have currently, works great and hiding and showing elements based on option selected. But doesnt work If i want 2 divs to show on based on sections. Help would be much appreciated.
$(function() {
$('#colorselector').change(function() {
$('.colors').hide();
$('#' + $(this).val()).show();
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<Select id="colorselector">
<option value="red">Red</option>
<option value="yellow">Yellow</option>
<option value="blue">Blue</option>
</Select>
<div id="red" class="colors" style="display:none"> red... </div>
<div id="yellow" class="colors" style="display:none"> yellow.. </div>
<div id="blue" class="colors" style="display:none"> blue.. </div>
2
Answers
Not sure what 2 div’s you want to show, but hes an example. I’ve switch out id for a command class by color:
Demo
If you want to hide/show more than one element then you should work with class names instead of IDs: