title: replace element, nested elements tag type javascript/jquery
body: <p>I have a <code>&lt;div&gt;</code> wrapped around a set of nested <code>&lt;div&gt;</code> elements; I'd like to present this as a drop-down menu. The element is part of a plugin I'm using on a WordPress website but this should still be adjustable using custom script.</p>
  <p>I would like to replace the encasing div with a <code>&lt;ul&gt;</code>, and turn all of the inner <code>&lt;div&gt;</code>s into <code>&lt;li&gt;</code> elements, so I can show this as a drop-down. Either that or a <code>&lt;select&gt;</code>, with nested <code>&lt;option&gt;</code> tags.</p>
  <p>Is there a way I can change the HTML tag type , or replace the div, using pure JavaScript, or jQuery?</p>
  <p>From:</p>
  <pre><code>&lt;div class=&quot;slots&quot;&gt;
     &lt;div class=&quot;availableslot&quot;&gt;&lt;/div&gt;
     &lt;div class=&quot;availableslot&quot;&gt;&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  <p>to:</p>
  <pre><code>&lt;ul class=&quot;slots&quot;&gt;
     &lt;li class=&quot;availableslot&quot;&gt;&lt;/li&gt;
     &lt;li class=&quot;availableslot&quot;&gt;&lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  <p>or:</p>
  <pre><code>&lt;select class=&quot;slots&quot;&gt;
     &lt;option class=&quot;availableslot&quot;&gt;&lt;/option&gt;
     &lt;option class=&quot;availableslot&quot;&gt;&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  <p>The isolated code: <a href="https://codepen.io/bolti95/pen/rNpMdJx" rel="nofollow noreferrer">https://codepen.io/bolti95/pen/rNpMdJx</a></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>  //div into list
  const slots_list = document.createElement("ul");
  var slots = document.getElementsByClassName("slots")
  console.log(slots)
  slots.insertBefore(slots_list, slots.children[0])</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.slots {
      width: 100% !important;
      height: max-content;
      border: none !important;
      box-shadow: none !important;
      margin: auto;
  }
  
  .slots div a {
      color: #77635A;
      background: none !important;
  }
  .slots div a:hover {
      background-color: #F7F7F7 !important;
      transition: 0.6s;
  }
  .availableslot {
      width: 120px;
      height: 55px;
      border-radius: 30px;
      margin-bottom: 25px; 
      margin: 10px;
      border: none !important;
      border-width: 0px;
      text-align: center;
      font-size: 20px !important;
      background-color: #EFE8DA;
      color: #77635A; 
  }
  
  .availableslot a {
      margin: 10px;
  }
  
  .availableslot:hover {
      outline: 1px solid #5FDEAB;
      background-color: #F7F7F7;
      transition: 0.6;
  }
  .availableslot a:hover {
      background-color: #F7F7F7;
      color: #5FDEAB;
      transition: 0.6s;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;meta charset="&lt;?php bloginfo('charset'); ?&gt;"&gt;
      &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;div class="slots"&gt;
        &lt;span&gt;03/22/2022&lt;/span&gt;
        &lt;br&gt;
        &lt;div class="availableslot"&gt;&lt;a&gt;11:00&lt;/a&gt;&lt;/div&gt;      
        &lt;div class="availableslot"&gt;&lt;a&gt;12:00&lt;/a&gt;&lt;/div&gt;
        &lt;div class="availableslot"&gt;&lt;a&gt;13:00&lt;/a&gt;&lt;/div&gt;
        &lt;div class="availableslot"&gt;&lt;a&gt;14:00&lt;/a&gt;&lt;/div&gt;
        &lt;div class="availableslot"&gt;&lt;a&gt;15:00&lt;/a&gt;&lt;/div&gt;
      &lt;/div&gt;
    &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>