What I'm trying to accomplish here basically is to utilize JQuery to show / hide an element based on the option value of the dropdown .
In this case I've included a paragraph , as you can see "RED" is selected by default , now what I want to do here is to basically hide the paragraph if the rest of the options are selected (blue / black / pink) and for the paragraph to continue to be hidden even after a page refresh until "RED" is selected again ,
Thank you !
$(document).ready(function(){
function Blue()
{
$(".visible").css("display", "none");
}
function Black()
{
$(".visible").css("display", "none");
}
function Pink()
{
$(".visible").css("display", "none");
}
$('#cars').on('change', function() {
if ( $('#cars').val() == 'Blue' ) Blue();
else if ( $('#cars').val() == 'Black' ) Black();
else if ( $('#cars').val() == 'Pink' ) Pink();
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select id="cars">
<option value="Red" selected="selected">Red</option>
<option value="Blue">Blue</option>
<option value="Black">Black</option>
<option value="Pink">Pink</option>
</select>
<p class="visible"> Visible Paragraph </p>