Note that there are some explanatory texts on larger screens.

plurals
  1. POVery unusual JavaScript behaviour
    primarykey
    data
    text
    <p>Here is something that I've used for ages now and all of the sudden I get these strange behaviours, maybe someone knows the reason why? Here is my HTML:</p> <pre><code>&lt;div class="tooltip" id="tooltip"&gt;&lt;/div&gt; &lt;input type="button" name="hide" value="hide" onclick="hide('tooltip');" /&gt; &lt;input type="button" name="show" value="show" onclick="show('tooltip');" /&gt; </code></pre> <p>Here is the JavaScript below the HTML code:</p> <pre><code> &lt;script type="text/javascript"&gt; function hide(id) { document.getElementById(id).style.display = 'none'; } function show(id) { document.getElementById(id).style.display = ''; } &lt;/script&gt; </code></pre> <p>Now there shouldn't be anything wrong with this code. It should hide or show tooltip on each button click. Now the weird thing going on is when I click on the hide button it hides itself, and when I click on show nothing happens. Hide is still hidden.</p> <p>Did anyone have similar problem? Is there a work-around for it? Maybe another approach for accomplishing the same thing (pure JavaScript)?</p> <p><strong>UPDATE:</strong> Changed it to block, still isn't working. I mean why would it hide the button I'm clicking on when there is no connection to that whatsoever? I'm using latest Firefox by the way. And I added alert in the function same thing. Here is re-written code:</p> <pre><code>function hide(id) { alert(id); document.getElementById(id).style.display = 'none'; } function show(id) { alert(id); document.getElementById(id).style.display = 'block'; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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