This code is working fine if ($(this).val() == "Spine") but not ($(this).val() == "Spine"||"Brian")
html, javascript, jquery
Solution
You have wrong syntax in using the logical or `||` operator
Change
if ($(this).val() == "Spine"||"Brain") {
To
if ($(this).val() == "Spine"|| $(this).val() == "Brain") {
You can use value with javascript object instead of val() of jquery object, as Fabrício Matté suggested. It would give you performance benefit.
if (this.value == "Spine" || this.value == "Brain")
Problem
This code is working fine if `($(this).val() == "Spine")` but if `($(this).val() == "Spine"||"Brian")` then the selection menu closes then opens again when the selection for `"optionbodyRegion" == ""` What am I doing wrong? ``` $("#optionbodyRegion").change(function(){ if ($(this).val() == "Spine"||"Brain") { document.getElementById('optioncontrast').options[0]=new Option("Select", "", false, false) document.getElementById('optioncontrast').options[1]=new Option("With", "With", false, false) document.getElementById('optioncontrast').options[2]=new Option("Without", "Without", false, false) document.getElementById('optioncontrast').options[3]=new Option("With and Without", "With and Without", false, false) $("#contrast").slideDown("fast"); //Slide Down Effect } else { if ($(this).val() == "" ) { $("#contrast").slideUp("fast"); //Slide Up Effect } } }); ```