Detecting whether a div is visible

Is there a way to detect whether any given DIV is visible? I.e., not only is .style.visibility set to visible, but that it isn't inside any other element that makes it invisible. We can exclude any issues of the element being out of view because below the screen fold, or covered up by something else (although that would be neat). The problem I'm having is that when I detect a DIV's visibility attribute, this doesn't tell me if it is overridden by some other DIV.
metalaureateAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kadabaCommented:
When you query for a div's attribute it will give you the specifics of the object or div in question.

try something like this... and see

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Div Test</title>
<script type="text/javascript">
function findVisibility(objektId,parentLevel){
	var objekt = document.getElementById(objektId);
	var parentCount = 0;
	do{
		if((objekt.style.display == "none")){
			alert("The object is invisible!");
			return;
		}
		objekt = fetchParent(objekt.id);
		parentCount++;
	} while(objekt && (parentCount<=parentLevel));
	
	alert("The object is visible!");
}

function fetchParent(objektId){
	return document.getElementById(objektId).parentNode;
}
</script>
</head>
<body id="contentBody">
<div id="test1">
	<div id="outerDiv1" style="display:block;">
		Outer Div Content 1
		<div id="innerDiv1" style="display:block;">
			Inner Div Content 1
		</div>
	</div>
	<input type="button" id="btnTest1" value="check div visibility 1" onclick="findVisibility('innerDiv1',1);">
</div>	
<hr>
<div id="test2">
	<div id="outerDiv2" style="display:block;">
		Outer Div Content 2
		<div id="innerDiv2" style="display:none;">
			Inner Div Content 2
		</div>
	</div>
	<input type="button" id="btnTest2" value="check div visibility 2" onclick="findVisibility('innerDiv2',1);">
</div>
<hr>
<div id="test3">
	<div id="outerDiv3" style="display:none;">
		Outer Div Content 3
		<div id="innerDiv3" style="display:block;">
			Inner Div Content 3
		</div>
	</div>
	<input type="button" id="btnTest3" value="check div visibility 3" onclick="findVisibility('innerDiv3',1);">
</div>

<hr>
<div id="test4">
	<div id="outerSec4" style="display:block;">
		<div id="outerDiv4" style="display:block;">
			Outer Div Content 4
			<div id="innerDiv4" style="display:block;">
				Inner Div Content 4
			</div>
		</div>
	</div>	
	<input type="button" id="btnTest4" value="check div visibility 4" onclick="findVisibility('innerDiv4',2);">
</div>
</body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
metalaureateAuthor Commented:
Thank you - helpful.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.