-2

I have the following conditional jquery function: Is there a way of having an "or" in a conditional? Ideally I want a single function, where if the values are 1,2 or 3 hide the corresponding elements. Is this possible? My goal is just to have more efficient, cleaner code, this seems unnecessarily long and reptitive.

$("#Catalogue").change(function () {
            var a = $(this).val();
            console.log(a);
            if (a == 1) {
                $("#DeliveryMethod").hide();
                $("#CatalogueID").hide();
            }
            else if (a == 2) {
                $("#DeliveryMethod").hide();
                $("#CatalogueID").hide();
            }
            else if (a == 3) {
                $("#CatalogueID").show();
                $("#DeliveryMethod").hide();
            }
            else {
                $("#DeliveryMethod").show();
                $("#CatalogueID").hide();
            }
        });
Mark
  • 4,773
  • 8
  • 53
  • 91

1 Answers1

0

Try

if(a == 1 || a == 2 || a == 3){ ... }

OR

if(a >= 1 && a <= 3){ ... }
Think Different
  • 2,815
  • 1
  • 12
  • 18