Here is my Javascript code
:
function expand(element) {
let viewbox = document.getElementById('viewbox');
viewbox.style.display = "block";
viewbox.innerHTML = "<h2 id='close' onclick='close()'>Х</h2><img id='inner_image' src='" + element.firstChild.src + "'>";
}
function close() {
let viewbox = document.getElementById('viewbox');
viewbox.style.display = "none";
}
When I try to trigger the close event, the div with the id viewbox
should disappear, but nothing happens. What did i do wrong?
here is code where expand()
function is used
<div class="conatiner" onclick="expand(this)"><img class="image" width="650" src="images/pizza1.jpg" alt="pizza"></div>
and here is code where close()
function should be used
<div id="viewbox" style="display: block;"><h2 id="close" onclick="close()">Х</h2><img id="inner_image" src="/images/image.jpg"></div>