Im trying to add in a close button for my div. It opens all ok but doesnt close and I cant fathom why ...
The code is here
window.onload = function display() {
document.getElementById("advert").style.display = "block";
}
function close() {
document.getElementById("advert").style.display = "none";
}
<div id="advert">
<div class="advert-content">
<button class="Close" onclick="close()">×</button>
<p>Content is here</p>
</div>
</div>
You can't use "close()" as a function name, it seems to be reserved (which makes kind of sense). Just use another name.
window.onload = function display() {
document.getElementById("advert").style.display = "block";
}
function xclose() {
document.getElementById("advert").style.display = "none";
}
<div id="advert">
<div class="advert-content">
<button class="Close" onclick="xclose()">×</button>
<p>Content is here</p>
</div>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With