I want to copy the input value when I click the div
, but I can't get it to work. Here is my code:
function handleClick() {
input.select();
document.execCommand("copy");
}
#input {
display: none
}
<div click="handleClick()">
<input type="text" value="test" id="input">
</div>
When I remove the css style of display: none
, it works.
Why can't I hide the input element? I just want to use input's .select()
, but don't want input show in my page, how can I do this?