title: Collapse accordian branch before expanding another?
body: <p>I have been working on someone else's webpage that has an accordian.</p>
  
  <p>Their relevant JQuery code portion is:</p>
  
  <pre><code> $(document).ready(function () {
              $(".accordion").on("click", ".trigger", function (n) {
                  var t, i;
                  n.preventDefault();
                  t = $(this).parent();
                  t.hasClass("open") ? t.find(".content").animate({ height: 0 }, 500, function () { t.removeClass("open") }) :
                      ($(".open .content").animate({ height: 0 }, 500, function () { $(this).parents(".open").removeClass("open") }),
                          i = t.find(".inner").height(), t.find(".content").animate({ height: i }, 500, function () { t.addClass("open"); $(this).height("auto") }))
              })
          });
  </code></pre>
  
  <p>I know I haven't uploaded the HTML (there's quite a lot) but I was hoping someone might be able to tell me how the jQuery code could be amended so any open branch collapses before the clicked one opens (only one is currently ever allowed to be open at a time).</p>
  
  <p>As present, because the branches contain a whole lot of images and text, the new branch isn't opening at the top of its content but rather for example half way down. I can see that if I manually collapse the previously opened branch first then open the new one, it all appears fine. So I thought if the code could be changed to close the old branch first it would have the scroll position of the new branch content correctly at located its top.</p>
  
  <p>UPDATE 1:
  Here's an HTML extract from the first branch which is opened on page load and contains a video.</p>
  
  <pre><code>&lt;ul class="accordion"&gt;
                  &lt;!-- Question 1 Start --&gt;
                  &lt;li class="open"&gt;
                      &lt;div class="trigger dvQuestionTitleTable dvQuestion1 dvQuestionAlignment"&gt;
                          &lt;div id="dvIDQuestion1" class="dvQuestionTitleRow" onclick="fJTogglePlusMinus(1)"&gt;
                              &lt;div class="theme-agent-heading-sub dvQuestionTitleTextCell"&gt;
                                  Video
                              &lt;/div&gt;
                              &lt;div id="dvIDPlusMinusImage1" class="dvQuestionTitleImageCell"&gt;
                                  &lt;img id="Image1" src="../../common/images/icons/icon-help-minus.svg" class="imgMinus"&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                      &lt;div class="dvTopHorizontalLineArea"&gt;
                          &lt;div class="dvHRLine"&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                      &lt;div class="content"&gt;
                          &lt;div class="inner"&gt;
                              &lt;div class="theme-help-answer"&gt;
                                  &lt;div class="dvVideoContainer1"&gt;
                                      &lt;video loop="" playsinline="" id="Video100" width="100%" controls="" poster="/pages/agent/resources/video/images/video-100-poster-image.jpg"&gt;
                                          &lt;source src="video/video-100.webm" type="video/webm"&gt;
                                          &lt;source src="video/video-100.mp4" type="video/mp4"&gt;
                                      &lt;/video&gt;
                                  &lt;/div&gt;
  </code></pre>