Search code examples
javascriptjqueryhtmlcopy-paste

Copy attribute value to clipboard


I already have it set up to where the page URL dynamically becomes the value of href (I can change the attribute or add one if needed). How can I make the link copy the href value to the clipboard?

I'm not looking for how to copy text from some other element by calling on it's id or class, I'm trying to make the link copy the text from the attribute in itself.

<li><a href='page.url'><i class='material-icons'>content_copy</i></a></li>

Solution

  • Don't recommend rolling out your own solution due to browser support quirks, however, there's a fully tested and trusted small 2 file library that already solves this problem (almost 20k stars on GitHub) clipboard.js that you should consider using, hope this helped you out.