Rather creating the span
element dynamically, use a intermediate function:
function copyfieldWithUniqueID(event) {
var uniqueID = uniqueID() // get a unique ID
return fieldtoclipboard.copyfield(event, uniqueID);
}
HTML:
<span onclick="copyfieldWithUniqueID(event)">Select All</span>
(Use onclick
instead of onClick
attribute)
And from the answer Create GUID / UUID in JavaScript?
Define a function:
function uniqueID() {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
s4() + '-' + s4() + s4() + s4();
}