JSFiddle - React, Tailwind, and code Playground
by Kolichikov
HTML
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Change jq</title>
<script src="https://code.jquery.com/jquery-3.4.1.js"></script>
</head>
<body>
<select name="sweets">
<option value="Chocolate">Chocolate</option>
<option value="Cakes">Cakes</option>
<option value="Caramel">Caramel</option>
<option value="Fudge">Fudge</option>
</select>
<div></div>
<div class='whoToSee' id="Chocolate" style='display:none'>
<h2 class="Chocolate">Chocolate</h2>
<strong>Who to see: </strong>Bob
<strong>Advice:</strong>Eat less of it
</div>
<div class='whoToSee' id="Cakes" style='display:none'>
<h2 class="Cakes">Cakes</h2>
<strong>Who to see:</strong>Sally
</div>
</body>
</html>
JavaScript
$( "select" )
.change(function () {
var str = "";
$( "select option:selected" ).each(function() {
str += $( this ).val() + "";
});
//$( "div" ).text( str );
//$('.whoToSee').show();
$(".whoToSee").hide();
$("#" + str).show();
//$('h2:contains(.str)') . show();
})
.change();