Note that there are some explanatory texts on larger screens.

plurals
  1. POHelp with closing popup div javascript
    text
    copied!<p>Can i get help correcting the code below? You can just copy and paste and try it yourself. Onmouseover the popup div appears. If i click(X) the popup div should close but it doesn't. Only doubleclicking (X) closes the popup div. Onmouseover it should always display a popup div though.</p> <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;/head&gt; &lt;style type="text/css"&gt; .container { display:block; width:500px; height:200px; border:1px solid green; } .advert { float:right; overflow:hidden; width:100px; height:30px; border:1px solid red; } .close { float:right; width:20px; height:28px; cursor:pointer; border:1px solid black; } &lt;/style&gt; &lt;body&gt; &lt;div class="container" onmouseover='getad(39);' onmouseout='hidead(39);changeback(39);'&gt; &lt;div class='advert' id="39" style="display:none;"&gt;&lt;div class="close"&gt;&lt;a href="javascript:closead(39)"&gt;X&lt;/a&gt;&lt;/div&gt;&lt;/div&gt; &lt;input type="text" value="1" id="ad39" /&gt; &lt;/div&gt; &lt;div class="container" onmouseover='getad(40);' onmouseout='hidead(40);changeback(40);'&gt; &lt;div class='advert' id="40" style="display:none;"&gt;&lt;div class="close"&gt;&lt;a href="javascript:closead(40)"&gt;X&lt;/a&gt;&lt;/div&gt;&lt;/div&gt; &lt;input type="text" value="1" id="ad40" /&gt; &lt;/div&gt; &lt;script type="text/javascript"&gt; function getad(number) { if(document.getElementById('ad'+number).value==1) { if(document.getElementById(number).style.display == "none") { document.getElementById(number).style.display = "block"; } } } function hidead(number) { if(document.getElementById('ad'+number).value==1) { if(document.getElementById(number).style.display == "block") { document.getElementById(number).style.display = "none"; } } } function closead(number) { document.getElementById('ad'+number).value = 0; if(document.getElementById(number).style.display == "block") { document.getElementById(number).style.display = "none"; } } function changeback(number) { if(document.getElementById('ad'+number).value==0) { document.getElementById('ad'+number).value = 1; } } &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload