Javascript copy text

Posted under » JavaScript on 1 Dec 2023

This refer to my Ajax live search article.

Rather than select and copy you can copy by pressing a button

function kopy() {
	  // get the container
	  const element = document.querySelector('#livesearch');
	  // Create a fake `textarea` and set the contents to the text
	  // you want to copy
	  const storage = document.createElement('textarea');
	  storage.value = element.innerHTML;

	  // Copy the text in the fake `textarea` and remove the `textarea`;
	  storage.setSelectionRange(0, 99999);
<input type="text" size="30" onkeyup="showResult(this.value)">
<p><div id="livesearch"></div>
  <button onclick="kopy()">Copy Me</button>

web security linux ubuntu python django git Raspberry apache mysql php drupal cake javascript css AWS data