Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If I'm just adding sprinkles of interactivity to a statically-rendered page for something that vanilla is good enough for (i.e. minimal-to-no display logic), I use the expando giving an element an `id` adds to `window`:

    <textarea id="userNotes"></textarea>
    <button type="button" id="copyButton">Copy</button>
    <script>
    copyButton.addEventListener('click', () => {
      navigator.clipboard.writeText(userNotes.value)
      copyButton.innerText = 'Copied'
      setTimeout(() => copyButton.innerText = 'Copy', 1000)
    })
    </script>


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: