Have you been looking for something like this? http://jsfiddle.net/tYvQ8/
$("#theSelect").change(function() { var value = $("#theSelect option:selected").val(); var theDiv = $(".is" + value); theDiv.slideDown().removeClass("hidden"); theDiv.siblings('[class*=is]').slideUp(function() { $(this).addClass("hidden"); }); });β
When the selection option changes, you
- Highlight the selected
div with slideDown() and delete its hidden class. - Find the siblings of the
div having "is" in the class name. (Be easier if the menu wasnβt a brother.) - Hide previously displayed siblings with
slideUp() , which takes a callback to add the hidden class after slideUp()
Here's another (in my opinion, best) way: http://jsfiddle.net/tYvQ8/1/
Get rid of your hidden class and use jQuery to hide them. Then you do not need to worry about adding and removing a class.
HTML without a hidden class
<body> <div class="selectContainer"> <select id="theSelect"> <option value="">- Select -</option> <option value="Patient">Patient</option> <option value="Physician">Physician</option> <option value="Nurse">Nurse</option> </select> </div> <div class="isPatient">Patient</div> <div class="isPhysician">Physician</div> <div class="isNurse">Nurse</div> </body>β
JQuery
$('[class^=is]').hide(); $("#theSelect").change(function(){ var value = $("#theSelect option:selected").val(); var theDiv = $(".is" + value); theDiv.slideDown(); theDiv.siblings('[class^=is]').slideUp(); });β
source share