Copy css rtl directional format to clipboard

How to copy CSS RTL directional format to clipboard?

I got this text on the clipboard: moc.liam@liam , but I want this: mail@mail.com

Using this code to copy:

<script>
function CopyKey(elementId) {
var aux = document.createElement("input");
aux.setAttribute("value", document.getElementById(elementId).innerHTML);
document.body.appendChild(aux);
aux.select();
document.execCommand("copy");
document.body.removeChild(aux);
}
</script>

<p id="key" class="rev" onclick="CopyKey('key')">moc.liam@liam</p>

.rev {
unicode-bidi: bidi-override;
direction: rtl;
}

EDIT (WORK CODE)

function Reverse(s){
  return s.split("").reverse().join("");
}

function CopyKey(elementId) {
  var aux = document.createElement("input");
  aux.setAttribute("value",    Reverse(document.getElementById(elementId).innerHTML));
  document.body.appendChild(aux);
  aux.select();
  document.execCommand("copy");
  document.body.removeChild(aux);
}
+4
source share
2 answers

JavaScript ignores css attributes. You need to write some code to flip the line.

function reverse(s){
    return s.split("").reverse().join("");
}

Please refer to this answer for more information on string inversion in JavaScript: fooobar.com/questions/20018 / ...

+5
source

Thanks for the answer, here is the working code.

function Reverse(s){
   return s.split("").reverse().join("");
}

function CopyKey(elementId) {
  var aux = document.createElement("input");
  aux.setAttribute("value", Reverse(document.getElementById(elementId).innerHTML));
  document.body.appendChild(aux);
  aux.select();
  document.execCommand("copy");
  document.body.removeChild(aux);
}
+1
source

Source: https://habr.com/ru/post/1688734/


All Articles