title: How to add class to element created using document.createElement?
body: <p>I have managed to add a class to the ul element but I can't get the syntax right to add classes to the li and a elements. Can anyone help please?</p>
  
  <pre><code>&lt;script&gt;
      anchors.options.placement = 'left';
      anchors.add('.entry-content h2');
      generateTableOfContents(anchors.elements);
  
      // External code for generating a simple dynamic Table of Contents
      function generateTableOfContents(els) {
        var anchoredElText,
            anchoredElHref,
            ul = document.createElement('UL');
            ul.className = "uk-nav uk-nav-default";
  
        document.getElementById('table-of-contents').appendChild(ul);
  
        for (var i = 0; i &lt; els.length; i++) {
          anchoredElText = els[i].textContent;
          anchoredElHref = els[i].querySelector('.anchorjs-link').getAttribute('href');
          addNavItem(ul, anchoredElHref, anchoredElText);
        }
      }
  
      function addNavItem(ul, href, text) {
        var listItem = document.createElement('LI'),
            anchorItem = document.createElement('A'),
            textNode = document.createTextNode(text);
  
        anchorItem.href = href;
        ul.appendChild(listItem);
        listItem.appendChild(anchorItem);
        anchorItem.appendChild(textNode);
      }
  &lt;/script&gt;
  </code></pre>