title: How can I move content into tabs from elsewhere on the page using javascript?
body: <p>I'm looking to move some content on a page, into a set of tabs higher on the page via javascript or any other means. I can't edit WHERE on the page this code exists, but I can set Pre/Post HTML on the fields and thus give it a class or an ID to mess with.</p>
  
  <p><a href="https://jsfiddle.net/zp9cs6jw/" rel="nofollow noreferrer">I built it out here to play with</a></p>
  
  <p>If you don't want to go there, here's the code:</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 openTab(evt, tabName) {
    var i, tabcontent, tablinks;
    tabcontent = document.getElementsByClassName("tabcontent");
    for (i = 0; i &lt; tabcontent.length; i++) {
      tabcontent[i].style.display = "none";
    }
    tablinks = document.getElementsByClassName("tablinks");
    for (i = 0; i &lt; tablinks.length; i++) {
      tablinks[i].className = tablinks[i].className.replace(" active", "");
    }
    document.getElementById(tabName).style.display = "block";
    evt.currentTarget.className += " active";
  }</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>/* Style the tab */
  .tab {
    overflow: hidden;
    border: 1px solid #ccc;
    background-color: #f9f9f9;
  }
  
  /* Style the buttons inside the tab */
  .tab button {
    background-color: inherit;
    float: left;
    border: none;
    outline: none;
    cursor: pointer;
    padding: 14px 16px;
    transition: 0.3s;
    font-size: 17px;
  }
  
  /* Change background color of buttons on hover */
  .tab button:hover {
    background-color: #ddd;
  }
  
  /* Create an active/current tablink class */
  .tab button.active {
    background-color: #0090bf;
    color: #fff;
  }
  
  /* Style the tab content */
  .tabcontent {
    display: none;
    padding: 6px 12px;
    border: 1px solid #ccc;
    border-top: none;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>```
  &lt;!-- I can edit this section as needed. --&gt;
  &lt;section class="panel panel-persondetails"&gt;
    &lt;div class="tab"&gt;
      &lt;button class="tablinks active" onclick="openTab(event, 'tab1')"&gt;Tab Name 1&lt;/button&gt;
      &lt;button class="tablinks" onclick="openTab(event, 'tab2')"&gt;Tab Name 2&lt;/button&gt;
      &lt;button class="tablinks" onclick="openTab(event, 'tab3')"&gt;Tab Name 3&lt;/button&gt;
    &lt;/div&gt;
  
    &lt;div id="tab1" class="tabcontent" style="display: block;"&gt;
      &lt;div&gt;
        replace me with stuff 1
      &lt;/div&gt;
    &lt;/div&gt;
  
    &lt;div id="tab2" class="tabcontent"&gt;
      &lt;div&gt;
        replace me with stuff 2
      &lt;/div&gt;
    &lt;/div&gt;
  
    &lt;div id="tab3" class="tabcontent"&gt;
      &lt;div&gt;
        replace me with stuff 3
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/section&gt;
  
  &lt;!-- The following is elsewhere on the page and I can't move it. I can add pre/post HTML which is how I'd wrap it in a div and give it an ID or class to hopefully use js to show it in the tabs above instead. --&gt;
  &lt;div id="content-tab-1"&gt;I want this in tab1.&lt;/div&gt;
  
  &lt;div id="content-tab-2"&gt;I want this in tab2.&lt;/div&gt;
  
  &lt;div id="content-tab-3"&gt;I want this in tab3.&lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Where are the JS experts locked in quarantine and itching for a problem to solve? Thanks all!</p>