Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Why don't you use a tab / something similar. Anyways, you can do this way, but before, change the HTML this way:</p> <pre><code>&lt;ul&gt; &lt;li&gt;&lt;a href="#tools"&gt;Tools&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#moulds"&gt;Moulds&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#videos"&gt;Videos&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; </code></pre> <p>And in the JavaScript give this way:</p> <pre><code>$("ul li a").click(function(){ theDiv = $(this).attr("href"); $(theDiv).show(); }); </code></pre> <p>If you want only one <code>div</code> to be shown, you can do this way:</p> <pre><code>$("ul li a").click(function(){ $("div").hide(); theDiv = $(this).attr("href"); $(theDiv).show(); }); </code></pre> <p>My suggestion would be, using a common class for both the <code>&lt;div&gt;</code>s and <code>&lt;a&gt;</code>s.</p> <hr> <p>Finally, you might arrive to this:</p> <pre><code>&lt;ul&gt; &lt;li&gt;&lt;a class="link" href="#tools"&gt;Tools&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a class="link" href="#moulds"&gt;Moulds&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a class="link" href="#videos"&gt;Videos&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;div class="tab" id="tools"&gt;This is the tools content&lt;/div&gt; &lt;div class="tab" id="moulds"&gt;This is the moulds content&lt;/div&gt; &lt;div class="tab" id="videos"&gt;This is the videos content&lt;/div&gt; </code></pre> <p>And then, the event handling would be:</p> <pre><code>$(".link").click(function(){ $(".tab").hide(); theDiv = $(this).attr("href"); $(theDiv).show(); }); </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