lundi 20 avril 2015

How to skip the second part of (JavaScript if statement) if the first part is false

I have this code:

  if (window.content.document.getElementById("error-msg") != null )
  {
    if (window.content.document.getElementById("error-msg").offsetParent !== null) 
    {
...
    }
  }

Can it be written in one if statement?

I tried the following...

if ( (window.content.document.getElementById("error-msg") != null) || (window.content.document.getElementById("error-msg").offsetParent !== null) ) {}

But, it didn't work, and produces an error:

TypeError: window.content.document.getElementById(...) is null

Aucun commentaire:

Enregistrer un commentaire