Jump to content

hide div when clicking elsewhere


turpentyne

Recommended Posts

I have a database generated list of images and hidden divs. When the user clicks on an image, the hidden div with that database-generated id appears. Simple enough. But I can't figure out how to make that div disappear when they click elsewhere.

 

 

I've got this, so far, but the Function to hide the div doesn't seem to be doing anything.

 

 

<script type="text/javascript">
var shownDiv;
var parDiv;

function showdiv(id,el){
document.getElementById(id).style.display = "block";
shownDiv=id;
parDiv=el.id;
}

function hideDiv(e){

var target=e?e.target:event.srcElement;
if(shownDiv&&target.id!=parDiv){
document.getElementById(shownDiv).style.display = "none";
}
}


document.onclick=hideDiv;

</script>

<!-- php code is here, and it generates each image in code like this. The first line shows where the showdiv is activated -->
<a class'hide' href="#%4\$s" target="_self" onclick="showdiv('%4\$s',this);" ><img src="%3\$s" style="border: solid 0px #000000;max-width:150px;"></a></div>

<!-- this is the hidden div -->
<div id="%4\$s" style="display:none;width:700px;z-index:109;height:0px;overflow:visible;color:#000;overflow:visible;scrollbar:none;">
data here: %4\$s
</div>



Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.