I have a select dropdown with options and I want to display a certain div depending on the selection in the dropdown.
Technically, I believe the easiest way would be to set divs that shouldnt be visible just to display: none by applying the right css class.
However, I don't know how to create the respective JS/jQuery code. I have looked at other solutions here for the last half and hour but they were more unique to their problem, while I belive my solution could be very simple.
Could someone please help me?
Thank you very much!!
Best, David
$(document).ready(function () {
$("#LooseTea").hide();
$('#PyramidBags').show();
$('#ProductSelect-product-template-option-0').change(function () {
if($("#ProductSelect-product-template-option-0").val()=="Loose Tea")
{
$("#LooseTea").show();
$("#PyramidBags").hide();
}
else
{
$("#PyramidBags").show();
$("#LooseTea").hide();
}
})
});
<select id="ProductSelect-product-template-option-0">
<option value="Pyramid Bags">Praymid Bags</option>
<option value="Loose Tea">Loose Tea</option>
</select>
<div class="">
<p>This text is about the first product</p>
</div>
<div class="">
<p>This textis about the second product</p>
</div>