I am trying to create a button that doesn't use ID to copy text from an input text field.
I thought the best way to do this would be using an event listener and then on click activate the function that would copy text from the input value.
HTML:
<div>
<input type="text" value="copy this" readonly>
<button type=button id='btn'>Copy URL</button>
</div>
JS:
<script>
document.querySelect('#btn').addEventListener('click', function() {
jimsFunction();
});
function jimsFunction() {
var copyText = document.getElementByTagName('input').value;
copyText.select();
copyText.setSelectionRange(0, 99999);
navigator.clipboard.writeText(copyText.value);
alert("Copied: " + copyText.value);
}
</script>
Can someone point out what I'm doing wrong here?
Thanks
tagis elements . You were missedsTry it :
You are duplicate
id, you should change toclass