<a href="javascript:void(0)" onclick = "document.getElementById('light3').style.display='block';document.getElementById('fade').style.display='block'"><button type="button" name="" value="" id="readmorelink3">+<span class="rmore">Read More</span></button></a>
I'm using the above DOM classic onClick
to simply display divs as a simple pop-up. I have created a close button within the div but I would also like to have the open divs hide
when the user clicks the body
or anywhere that isn't the open div. I have tried absolutely everything --
My simple Overlay (1 of 3)
<!-- read more overlays 1 -->
<div id="light" class="white_content">
<a class="close" href="javascript:void(0)" onclick = "document.getElementById('light').style.display='none';document.getElementById('fade').style.display='none'" class="textright" style="color: #DDD !important; float:right;">CLOSE X</a>
<h4>[Hey+]</h4>
<h3>Demo</h3>
<h3>SUP</h3>
<span> 2.5 fl. oz.</span><br>
<br>
<p>
Cool content, about cool things.
</p>
</div>
<!-- // read more overlays 1-->
I tried this guy:
$(document).click(function() {
$('#mydiv').fadeOut(300);
});
I've messed with this guy:
if($('#mydiv').is(":not(:visible)") ){
// and visa versa if visible etc
Also have tried.
// To prevent hide #menu when click on #main
$('#mydiv').click(function (e) {
e.stopPropagation();
});
// Click outsite of #menu
$('html').click(function () {
$('#mydiv').hide();
});
Realizing I have should have done this with simple jQuery and not inline; but I don't want to redo everything so seeking DOM / JavaScript solution. Simply to close the open or display: block divs > when they are displayed, by in addition clicking outside of the element or on body tag.
EG: DIV OVERLAY IS DISPLAYED > CLICK OUTSIDE OF ELEMENT AND IT CLOSES. I ADDED ONCLICK CLOSE BUTTON TO THE BODY TAG, BUT IT KILLED POPUP ENTIRELY, ADDED A WRAPPER, NO CIGAR.