We don't need 13 minutes tutorial to copy a text. This is a very easy way to copy your text: document.querySelector("#copy-url-btn").onclick = function () { navigator.clipboard.writeText(document.querySelector("#copy-url-text").innerText); };
the code is the same document.getElementById('btncopy').onclick = function() { const _this = this navigator.clipboard.writeText(document.getElementById('para').innerText).then(function(){ _this.innerText ='Copied'
setTimeout(function(){ _this.innerText = 'Copy' }, 1000) }) } but my console is getting this error and I don't know why. Uncaught TypeError: Cannot set properties of null (setting 'onclick') at script.js:1:44
We don't need 13 minutes tutorial to copy a text. This is a very easy way to copy your text: document.querySelector("#copy-url-btn").onclick = function () {
navigator.clipboard.writeText(document.querySelector("#copy-url-text").innerText);
};
Thanks. Really helpful
No problem! I'm glad to hear that
Thanks a lot
You're welcome!
Excelente, Obrigado.
How can I use the clipboard API with http requests?
I followed this instruction but it does not work when I duplicate for another 'copy-text' to copy.
Can you paste your JavaScript code here? I can look at it
the code is the same
document.getElementById('btncopy').onclick = function() {
const _this = this
navigator.clipboard.writeText(document.getElementById('para').innerText).then(function(){
_this.innerText ='Copied'
setTimeout(function(){
_this.innerText = 'Copy'
}, 1000)
})
}
but my console is getting this error and I don't know why.
Uncaught TypeError: Cannot set properties of null (setting 'onclick')
at script.js:1:44
I have the same error did you figure out how to fix it?