Answers for "how to copy a text in javascript"

18

copy text to clipboard javascript

//As simple as this
navigator.clipboard.writeText("Hello World");
Posted by: Guest on February-23-2021
1

copy text to clipboard javascript

<script>
function copyToClipboard(element) {
  var $temp = $("<input>");
  $("body").append($temp);
  $temp.val($(element).text()).select();
  document.execCommand("copy");
  $temp.remove();
}
</script>

<p id="text">Hello</p>
<button onclick="copyToClipboard('#text')"></button>
Posted by: Guest on July-24-2020
0

js copy text to clipboard

// promise is returned for outcome;
// might require browser permissions;
// prefer this API as "execCommand" is deprecated
navigator.clipboard.writeText("some text").then(function() {
  /* clipboard successfully set */
}, function() {
  /* clipboard write failed */
});
Posted by: Guest on April-07-2022

Code answers related to "how to copy a text in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language