user2512696
user2512696

Reputation: 325

if Statement - Multiple Conditions

I am looking to use an if statement to check whether e.currentTarget.id doesn't equal "alert" OR "history" and this is not working. Is there another way to check two conditions for an either/or situation like this one?

  var buttons = elt.find(":submit,:button,.clickable");
  buttons.unbind("click");
  buttons.click(function (e) {
    put({ "tag": "click",  "id": e.currentTarget.id});
    if(e.currentTarget.id != "alert" || e.currentTarget.id != "history"){
        $(".hide_on_click").hide();
    }
  });

Upvotes: 0

Views: 143

Answers (1)

Kristian Barrett
Kristian Barrett

Reputation: 3762

Your statement will always be true since the id cannot equal two different strings and thus one of them will always be true.

  var buttons = elt.find(":submit,:button,.clickable");
  buttons.unbind("click");
  buttons.click(function (e) {
    put({ "tag": "click",  "id": e.currentTarget.id});
    if(e.currentTarget.id != "alert" && e.currentTarget.id != "history"){
        $(".hide_on_click").hide();
    }
  });

I am not sure what it is you want to do; but if you want to hide something when the id is none of those values try the above code.

Upvotes: 5

Related Questions