i want to set setTimeout function in copy button so that if user click copy then text will be "copied" after that it will return to "copy" after 3-4sec. please Help me to solve this prblm and also help me to make it more light weight js.
Below is my html code
<blockquote>
<p id="myInput">Lines of code Here</p>
<button id="btn1">Copy</button>
</blockquote>
Js code
<script>
function copyFunction() {
const copyText = document.getElementById("myInput").textContent;
const textArea = document.createElement('textarea');
textArea.textContent = copyText;
document.body.append(textArea);
textArea.select();
document.execCommand("copy");
btn1.innerText = "copied";
textArea.remove();
}
document.getElementById('btn1').addEventListener('click', copyFunction);
</script>
Just a pointer, in your code you reference btn1 as a variable, but you have not shown where it is declared as a variable:
Anyway, it's simple enough, something like this could work, in vanilla JS: