-
Notifications
You must be signed in to change notification settings - Fork 287
/
Copy pathapp.js
34 lines (30 loc) · 1.08 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const copyText = document.querySelector("textarea[name=copyTxt");
const finalText = document.querySelector("textarea[name=finalTxt");
const moveBtn = document.querySelector(".moverBtn");
const copyBtn = document.querySelector(".copyBtn");
const output = document.querySelector(".output");
copyBtn.addEventListener("click", () => {
let temp = copyText.value;
copyToClipBoard(temp);
});
moveBtn.addEventListener("click", () => {
let temp = copyText.value;
finalText.value = temp;
});
copyText.addEventListener("click", () => this.select());
finalText.addEventListener("click", () => this.select());
function copyToClipBoard(str) {
const outputContainer = document.querySelector(".output-container");
const textarea = document.createElement("textarea");
textarea.value = str;
outputContainer.appendChild(textarea);
textarea.select();
document.execCommand("copy");
outputContainer.removeChild(textarea);
output.innerHTML = `<h3>Content Copied </h3>`;
output.classList.add("added");
setTimeout(() => {
output.classList.toggle("added");
output.textContent = "";
}, 2000);
}