Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's called <strong>accordion</strong> and the easyest way to build it is:</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>$('.qa h3').click(function(){ $(this).next().slideToggle(); });</code></pre> <pre class="snippet-code-css lang-css prettyprint-override"><code>.qa &gt; *{margin:0; padding:8px 16px;} /* all */ .qa &gt; h3{cursor:pointer; border-top: 1px solid #eee;} /* questions */ .qa &gt; div{display:none;} /* Hide all answers */</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt; &lt;div class="qa"&gt; &lt;h3&gt;Question 1&lt;/h3&gt; &lt;div&gt;answer 1...&lt;/div&gt; &lt;h3&gt;Question 2&lt;/h3&gt; &lt;div&gt;answer 2...&lt;/div&gt; &lt;h3&gt;Question 3&lt;/h3&gt; &lt;div&gt;answer 3...&lt;/div&gt; &lt;/div&gt;</code></pre> </div> </div> </p> <h2>To close previously opened ones and toggle clicked one:</h2> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>$('.qa').each(function() { var $q = $(this).find("&gt; h3"), $a = $(this).find("&gt; div"); $q.click(function() { var $qa = $(this).next(); // Get the question's answer $a.not($qa).slideUp(); // Close all answers (not the next's one) $qa.slideToggle(); // Toggle answer }); });</code></pre> <pre class="snippet-code-css lang-css prettyprint-override"><code>.qa &gt; *{margin:0; padding:8px 16px;} /* all */ .qa &gt; h3{cursor:pointer; border-top: 1px solid #eee;} /* questions */ .qa &gt; div{display:none;} /* Hide all answers */</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt; &lt;div class="qa"&gt; &lt;h3&gt;Question 1&lt;/h3&gt; &lt;div&gt;answer 1...&lt;/div&gt; &lt;h3&gt;Question 2&lt;/h3&gt; &lt;div&gt;answer 2...&lt;/div&gt; &lt;h3&gt;Question 3&lt;/h3&gt; &lt;div&gt;answer 3...&lt;/div&gt; &lt;/div&gt;</code></pre> </div> </div> </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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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