James James - 6 months ago 45
Javascript Question

jQuery not equals to conditions not working

I am likely missing something very obvious here but I have 2 values I need to check

if(data['width'] != 2000 || data['width'] != 750){

I want to show the image warning if the returned value is not 2000 or 750 but seems to be showing all the time.

Answer Source

Your logic is flawed. You can't use a negative check like this with an or condition, because if one side fails the other will hit, hence the condition is always true. You need to use a logical and condition instead:

if (data['width'] != 2000 && data['width'] != 750){
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download