Check if an element is visible to the user
Login or Register to Bookmark this snippet
This function checks the CSS properties to see if the element is actually visible to the user. Sometimes useful for form validation, to make sure you're not validating a hidden field.
Requires xGetElementById (also available on this site).
function isVisible(e) {
//returns true is should be visible to user.
if (typeof e == "string") {
e = xGetElementById(e);
}
while (e.nodeName.toLowerCase() != 'body' && e.style.display.toLowerCase() != 'none' && e.style.visibility.toLowerCase() != 'hidden') {
e = e.parentNode;
}
if (e.nodeName.toLowerCase() == 'body') {
return true;
} else{
return false;
}
}
Added by JC on 12th November, 2007
There are no comments about this snippet.
You must be registered and logged in to post a comment.
Login here to post a comment