Note that there are some explanatory texts on larger screens.

plurals
  1. POHiding and showing div blocks in html
    primarykey
    data
    text
    <p>I am a beginner to html and in the below code , i have tried to hide and show contents using div blocks. I am able to hide/ show the second div block but on clicking the first div block it doesn't work! Dunno where it is going wrong. Any help would be appreciated.<a href="https://i.stack.imgur.com/UAAHZ.png" rel="nofollow noreferrer"></a></p> <pre><code>&lt;html&gt; &lt;body&gt; &lt;script type="text/javascript"&gt; function hideshow(which) { if (!document.getElementById) return if (which.style.display=="block") which.style.display="none" else which.style.display="block" } &lt;/script&gt; &lt;table&gt; &lt;tr&gt;&lt;td&gt;&lt;a href="javascript:hideshow(document.getElementById('adiv1'))"&gt;&lt;label class="menuOff" style="font-size: 35px;"&gt;Div block 1&lt;/label&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt; &lt;div id="adiv1" style="font:24px bold; display: none;"&gt; &lt;table&gt; &lt;tbody&gt; &lt;tr&gt;&lt;td&gt;Now you see me&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;Hello&lt;/td&gt;&lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/div&gt; &lt;tr&gt;&lt;td&gt;&lt;a href="javascript:hideshow(document.getElementById('adiv'))"&gt;&lt;label class="menuOff" style="font-size: 35px;"&gt;Div block 2&lt;/label&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt; &lt;div id="adiv" style="font:24px bold; display: none;"&gt; &lt;table&gt; &lt;tbody&gt; &lt;tr&gt;&lt;td&gt;Now you see me&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;Hello&lt;/td&gt;&lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/div&gt; &lt;/table&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><img src="https://i.stack.imgur.com/UAAHZ.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
    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