Simple Javascript "undefined" question -


i'm iterating on bunch of child nodes , checking see if visible on page statement:

if(child.offsetwidth == 0 || child.offsetheight == 0 || child.style.visibility == 'hidden'     || child.style.display == 'none'){ 

child defined in loop that's not issue.

what issue elements might not have style attribute defined , javascript returns "child.style" not defined.

how do seemingly simple if statement without stopping because not defined?

i tried doing this:

if(undefined !== child.style){ var addquery = "child.style.visibility == 'hidden' ||     child.style.display == 'none'"; } if(child.offsetwidth == 0 || child.offsetheight == 0 || addquery){ console.debug(child); } 

but think addquery evaluating true , not working.

if(child.offsetwidth == 0 || child.offsetheight == 0 || (child.style && (child.style.visibility == 'hidden' || child.style.display == 'none'))) 

since && short-circuit operator, evaluate child.style.visibility == 'hidden' || child.style.display == 'none' if child.style evaluates true, meaning child.style exists, , therefore can accessed. if child.style evaluates false, rest ignored; child.style won't accessed, , therefore no errors thrown.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -