Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If I understand this correctly, you want to toggle the information below a link, right? To do this for all elements which do have the same markup, you can use jquery's context feature within the selector. And you might want to restructure your markup to support parent/child selectors.</p> <p>If you markup looks like this for example: </p> <pre><code>&lt;a class="toggleAll"&gt;Toggle all&lt;/a&gt; &lt;div class="item"&gt; &lt;a href="#" class="link"&gt;Link&lt;/a&gt; &lt;ul class="info"&gt; &lt;li&gt;lala&lt;/li&gt; &lt;li&gt;blub&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div class="item"&gt; &lt;a href="#" class="link"&gt;Link&lt;/a&gt; &lt;ul class="info"&gt; &lt;li&gt;lala&lt;/li&gt; &lt;li&gt;blub&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; </code></pre> <p>The JavaScript to toggle all and toggle one element when the user clicks the link is pretty simple: </p> <pre><code>$(document).ready(function () { $(".toggleAll").click(function () { $(".info").toggle(); }); $(".item .link").click(function (e) { $(".info", $(this).parent()).toggle(); }); }); </code></pre> <p>So this should really simplify your code a lot, it just depends on how you structure your markup. Of cause instead of class names you can also use IDs or names or whatever to identify your items.</p> <p>:edit: To goggle all other items and to have a default state on page load you can modify the script like this:</p> <pre><code>$(document).ready(function () { $(".hideAll").click(function () { $(".info").hide(); }); $(".showAll").click(function () { $(".info").show(); }); $(".item .link").click(function (e) { var currentInfo = $(".info", $(this).parent()); $(".info").not(currentInfo).hide(); $(currentInfo).show(100); }); $(".info").hide(); $(".info").first().show(); </code></pre> <p>});</p>
    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.
    1. This table or related slice is empty.
    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