When the batman image is clicked on it shows the 'overlay' div however that div is not clickable for some reason thus not allowing the onclick portion of the code to run. Deleting the 'document.body..... ' line of code solves this issue but why?
JS:
window.onload = function()
{
$("#overlay").hide();
}
$(document).ready(function(){
//page is ready
$("#overlay").on("click",function(){
alert("hi");
$("#overlay").fadeOut(500);
});
$('#batman').on("click",function(){
lightboxImg()
});
});
function lightboxImg()
{
var source = $('#batman').attr('src');
var text = "<img src= \"" + source + "\" id=\"lightbox-img\"/>";
document.body.innerHTML = text + document.body.innerHTML;
$("#overlay").fadeIn(0);
}
HTML:
<!DOCTYPE html>
<html>
<head>
<title> Lightbox </title>
<link rel="stylesheet" type="text/css" href="lightboxcss.css">
</head>
<body>
<div id = "overlay"></div>
<img src="batman.jpg" alt="" href="javascript:void(0)" id="batman" >
<br><br><br><br>
<p> RANDOM TEXT STUFF </p><br><br>
<p> 328ueekfuuirgh40t43h8hohro8ht </p>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="lightboxjs.js"> </script>
</body>
</html>