Okay -- I'm not sure I understand exactly how this would work. I'll look forward to the sample code (doesn't have to be huge -- just enough to make sure I understand what you mean).
Thanks,
Phil
Main Topics
Browse All TopicsHello Javascript Experts.
What I want is to be able to have a div show up on a page when a user clicks a button (display=block, this part is no problem), and then when the user clicks anywhere outside the parent div for the div and all child content to go away (onblur).
So, I have the following code format:
<div onBlur="this.style.display
Stuff in Parent
<div id="Child1" class="Child1">Stuff in Child 1</div>
<div id="Child2" class="Child2">Stuff in Child 2</div>
</div>
The problem with this is that when the children get focus, onBlur fires for the parent and the div disappears. I would like to have the parent div stay visible (display=block) as long as the user is doing anything (clicking) in the parent or any of its children. Clicking a child should not cause the parent to disappear. This is my current problem.
Thank you in advance for your help.
Regards,
Phil / peh803
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
<html>
<head>
<script language="javascript">
function showhide(evt) {
if (!evt) { evt = window.event; }
if (document.all) { trgObj = evt.srcElement; }
else { trgObj = evt.target; }
if (!trgObj) { return; }
if (!trgObj.id) { return; }
if (trgObj.id != 'parentDiv') {
document.getElementById('p
}
else {
trgObj.style.display = 'block';
}
}
</script>
</head>
<body onclick="showHide(event);"
<div onBlur="this.style.display
Stuff in Parent
<div id="Child1" class="Child1">Stuff in Child 1</div>
<div id="Child2" class="Child2">Stuff in Child 2</div>
</div>
</body>
</html>
Here is a complete example
<html>
<head>
<script language="javascript">
function getParent (src, tgName)
{
while (src.parentNode != null)
{
if (src.parentNode.tagName == tgName)
{
return src.parentNode;
}
src = src.parentNode;
}
return src;
}
function showHide(evt) {
if (!evt) { evt = window.event; }
if (document.all) { trgObj = evt.srcElement; }
else { trgObj = evt.target; }
if (!trgObj) { return; }
if (!trgObj.id) {
document.getElementById('p
return;
}
if ( (trgObj.tagName == 'DIV') && (trgObj.id != 'parentDiv'))
{
var tObj=null;
tObj =getParent(trgObj, 'DIV');
if (tObj) { trgObj = tObj; }
}
if (trgObj.id != 'parentDiv') {
document.getElementById('p
}
else {
trgObj.style.display = 'block';
}
}
</script>
</head>
<body onclick="showHide(event);"
<style type="text/css">
.parentDiv {
width: 400px;
border: solid black;
height: 400px;
}
</style>
<H1>DOCUMENT Elements will go here.</H1>
<a href="#" onmouseover="document.getE
<div id="parentDiv" class="parentDiv">
Stuff in Parent
<div id="Child1" class="Child1">Stuff in Child 1</div>
<div id="Child2" class="Child2">Stuff in Child 2</div>
</div>
<H1>Another documents elements will go here.</H1>
</body>
</html>
I have a quick follow-up question on this -- I'd also be happy to open another question if you want me to.
Let's say I want to show the div not onMouseOver, as in the provided example, but instead, onClick of the anchor tag. Since the body's onClick event is already doing this: showHide(event); I don't believe that simply changing the "onmouseover" to "onclick" will do it (I have tried this, and clicking the link does not seem to work).
So, how can I modify the code slightly to use onclick to show the div initially instead of onMouseOver?
Thanks,
Phil
Business Accounts
Answer for Membership
by: TedInAKPosted on 2006-08-23 at 13:26:06ID: 17375934
Maybe you could use a global var for each child to say "i'm open!". I'll be back with some code in a bit.