JSFiddle - React, Tailwind, and code Playground
by Kiya_Iekret
HTML
<input type="text" id="alfanope" value="drghfhfgh"/><button data-do-schowka="#alfanope">A</button>
<input type="text" id="betanope" value="56756"/><button data-do-schowka="#betanope">B</button>
<input type="text" id="gammanope" value="tdfg"/>
JavaScript
'use strict';
(function() {
//clicking sensor
document.body.addEventListener('click', kopiujDoSchowka, true);
function kopiujDoSchowka(zaznaczenieCoSkopiować) {
//point to the thing to copy
const zaznaczenieIstnieje = zaznaczenieCoSkopiować.target.dataset.doSchowka;
var kopiowanaTreść = zaznaczenieIstnieje ? document.querySelector(zaznaczenieIstnieje) : null;
//check if it can be copied
if (kopiowanaTreść && kopiowanaTreść.select) {
kopiowanaTreść.select();
try {
document.execCommand('copy');
kopiowanaTreść.blur();
}
catch (err) {
alert('CTRL+C INSTEAD & FIX THIS');
}
}
}
})();
//onclick select the input field then fire ^
document.body.addEventListener('focus', )