0

i'm very new to JS so be nice haha, but i'm trying to create a table of contents on a page using the DOM.

const h2 = document.querySelectorAll('h2');
const toc = document.querySelector('#toc')

h2.forEach(heading => {
    toc.innerHTML = `<li><a href="">${heading}</a></li>`
})

it's not working how i would expect tbh. any help is appreaciated, i'm probably just being dumb

tylerlecho
  • 73
  • 8
  • 4
    "it's not working how i would expect tbh" — Tell us what it **is** doing, not just what it isn't. Tell us what you expect, don't make us guess. – Quentin Aug 21 '21 at 21:19
  • ah sorry, i expect it to go through the h2's, print them each out as an
  • on the DOM
  • – tylerlecho Aug 21 '21 at 21:21