Toggle all accordion tabs closed before opening another (only one open at a time)
<p>I'm using JQuery and JQuery UI to build a small web application that is based around an accordion. I have the accordion logic figured out, but I'm having some trouble getting the result I want. I want all of the tabs to collapse when one is clicked, but I'm not sure how to do that.</p>

<p>Google didn't help me at all, before the serial downvoters nab me. Couldn't find anything on here, either.</p>

<p>Here is my HTML:</p>

<pre><code>&lt;button class="accordion"&gt;About&lt;/button&gt;
        &lt;div class="panel"&gt;
            &lt;p&gt;Blah 1&lt;/p&gt;
        &lt;/div&gt;
        &lt;button class="accordion"&gt;Contact&lt;/button&gt;
        &lt;div class="panel"&gt;
            &lt;form&gt;
                &lt;label&gt;Full Name&lt;/label&gt;
                &lt;input type="text" /&gt;
                &lt;label&gt;E-mail Address&lt;/label&gt;
                &lt;input type="email" /&gt;
            &lt;/form&gt;
        &lt;/div&gt;
</code></pre>

<p>My CSS:</p>

<pre><code>button.accordion {
    background-color: #336699;
    background: linear-gradient(-90deg, #fff, #336699, #fff);
    color: #fff;
    cursor: pointer;
    padding: 18px;
    width: 100%;
    border: none;
    text-align: center;
    outline: none;
    font-size: 15px;
    transition: 0.4s;
}

button.accordion:not(:last-child) {
    margin-bottom: 10px;
}

button.accordion .active,
button.accordion:hover {
    background-color: #555;
}

div.panel {
    padding: 0 18px;
    background-color: white;
    max-height: 0;
    overflow: hidden;
    transition: 0.6 ease-in-out;
    opacity: 0;
}

div.panel.show {
    opacity: 1;
    max-height: 500px;
}

div.column {
    float: left;
    width: 300px;
}
</code></pre>

<p>And finally, my JQuery:</p>

<pre><code>$(function() {
    $('.accordion').on('click', function() {
        // Something here, maybe?
        $(this).toggleClass('active', 400);
        $(this).next().toggleClass('show', 400);
    });
});
</code></pre>

<p>When I try to put something inside the callback to close all of them, it ends up getting executed immediately and the tabs don't open at all. Can someone please give me an explanation of what exactly is going on?</p>