Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 01/12/2024 in all areas

  1. That's correct: an ID will only ever refer to one element on the page, so using it for multiple elements is always incorrect. There's a simple solution for you here. Wrap the NOW PLAYING and the button (both) in a container element, then when the button is clicked, have it locate the container and then find the desired element to copy inside of it. IIRC: <div class="copy-container"> <div class="copy-target">NOW PLAYING: Something</div> <button class="copy-button">COPY</button> </div> <script> document .querySelectorAll(".copy-container") .forEach(container => { const target = container.querySelector(".copy-target"); const button = container.querySelector("btn.copy-button"); button.addEventListener("click", () => { copyToClipboard(target); }); }); </script> And please don't implement clipboard functions like that - use the actual Clipboard API instead.
    1 point
This leaderboard is set to New York/GMT-05:00
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.