title: jquery-ui accordion - How to dynamically create a new section
body: <p>I want to know whether there exists a method that I could add a new section using <a href="http://jqueryui.com/accordion/" rel="nofollow noreferrer">jQuery UI</a></p>
  
  <p>This is what I do so far without any error, but the accordion don't work since I add a new one</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>$( function() {
      $( "#accordion" ).accordion();
  
      $('#addNewSection').on('click', function() {
          var newH3 = document.createElement('h3');
          var newDiv = document.createElement('div');
          var acc = document.getElementById('accordion');
          var number = document.getElementsByTagName('h3').length;
  
          newH3.innerText = 'Section' + (parseInt(number) + 1) + "(This won't collapse)";
          newDiv.innerText = 'This is a new section after clicking the button';
          acc.appendChild(newH3);
          acc.appendChild(newDiv);
      });
  } );</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>h3 { background-color: "blue"; }
  div { background-color: "lightgreen"; }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id="accordion"&gt;
      &lt;h3&gt;Section 1 (collapsible)&lt;/h3&gt;
      &lt;div&gt;
          &lt;p&gt;
          This is the context in section 1
          &lt;/p&gt;
      &lt;/div&gt;
  
      &lt;h3&gt;Section 2 (collapsible)&lt;/h3&gt;
      &lt;div&gt;
          &lt;p&gt;
          This is the context in section 2
          &lt;/p&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;button id="addNewSection"&gt;AddOne&lt;/button&gt;
  
  &lt;script src="https://code.jquery.com/jquery-1.12.4.js"&gt;&lt;/script&gt;
  &lt;script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"&gt;&lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>How to fix it? Or is there any official method I can use?</p>