Skip to content

Instantly share code, notes, and snippets.

@BrynM
Last active December 14, 2015 23:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BrynM/5167601 to your computer and use it in GitHub Desktop.
Save BrynM/5167601 to your computer and use it in GitHub Desktop.
Test if a given HTML element is visible - isvis()
function isvis ( thing ) {
if ( typeof(thing) === 'object' ) {
try {
return ( thing instanceof HTMLElement ) &&
!( ( thing.offsetWidth === 0 ) && ( thing.offsetHeight === 0 ) );
} catch (e) {
return ( thing.nodeType === 1 ) &&
( typeof(thing.style) === 'object') &&
( typeof(thing.ownerDocument) ==='object') &&
!( ( thing.offsetWidth === 0 ) && ( thing.offsetHeight === 0 ) );
}
}
return false;
}
// use
var visible = isvis( document.getElementById( 'foo_elem' ) );
@BrynM
Copy link
Author

BrynM commented Mar 15, 2013

Pretty much public domain - copy/pasta good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment