Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Closing a div - javascript not wokring [duplicate]

Tags:

javascript

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()">&times;</button>
    <p>Content is here</p>
  </div>
</div>
like image 313
T.alcock Avatar asked Nov 20 '25 10:11

T.alcock


1 Answers

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()">&times;</button>
    <p>Content is here</p>
  </div>
</div>
like image 128
sascha10000 Avatar answered Nov 22 '25 01:11

sascha10000



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!