I have a small requirement. I need to show and hide divs based on the option selected. Below is my code. Ho to show all green and red class div's when I select 'all' option. It works for red and green options. Thanks in advance.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="colorselector">
<option>Choose Color</option>
<option value="all">All</option>
<option value="red">Red</option>
<option value="green">Green</option>
</select>
<div class="red box">You have selected <strong>red option</strong> so i am here</div>
<div class="green box">You have selected <strong>green option</strong> so i am here</div>
<script type="text/javascript">
$(function() {
$('#colorselector').change(function(){
$('.box').hide();
$('.' + $(this).val()).show();
});
});
</script>
.box{
color: #fff;
display: none;
margin-top: 20px;
}
.red{ background: #ff0000; }
.green{ background: #228B22; }