JSFiddle - React, Tailwind, and code Playground

by pamselle

HTML

<body id="example2">
  <p>Clicking the "Empty List" link should remove all the elements from the list, but it only removes some of them.</p>

  <ul id="example">
    <li>Item 1</li>
    <li>Item 2</li>
    <li>Item 3</li>
    <li>Item 4</li>
    <li>Item 5</li>
  </ul>
  <script>
  function emptyList(list_elem) {
    var items = list_elem.getElementsByTagName('li');

    for (var i = 0; i < items.length; i++) {
      list_elem.removeChild(items[i]);
    }
  }
  </script>

  <a id="demoLink" href="#">Empty List</a>
</body>

JavaScript

document.getElementById('demoLink').onclick = function() {
    emptyList(document.getElementById('example'));
    return false;
}