Home > Mobile >  Copying information at the click of a button
Copying information at the click of a button

Time:09-12

Script that copies information on button click and then returns the original text loses some of the button's content.

enter image description here

enter image description here

enter image description here

missing icon from Font Avesome. Can this be fixed somehow?

I'm a newbie, I'll be glad for a detailed answer.

html:

<p id="battlenet-id">gameid#26737</p>
<p id="xbox-id">gameid#5423</p>

<li><a href="javascript:void(0);"  onclick="copyToClipboard('battlenet-id', this)"><i ></i> Battle.net</a></li>
<li><a href="javascript:void(0);"  onclick="copyToClipboard('xbox-id', this);"><i ></i> Xbox</a></li>

js

function copyToClipboard(elementId, thisButton) {
  let oldText = thisButton.textContent
  thisButton.textContent = '!Copied!'
  const timeout = setTimeout(function() { thisButton.textContent = oldText }, 3000);
  var aux = document.createElement("input");
  aux.setAttribute("value", document.getElementById(elementId).innerHTML);
  document.body.appendChild(aux);
  aux.select();
  document.execCommand("copy");
  console.log("           
  • Related