VueJS: For text input, how to make it so that clicking on it will select everything?


VueJS: For text input, how to make it so that clicking on it will select everything?



I've found this: Copy to Clipboard that also works on Mobile?



But VueJS doesn't use jQuery. So what is the alternative to this?




2 Answers
2



You can still use JQuery, just add the script to your HTML, but if you don't want to use JQuery the alternative is to use vanilla Javascript (pure JS).



The setSelectionRange(start, end) method of an input is the answer you may want.


setSelectionRange(start, end)



Here's a demo.



Working demo


<input type="text" ref="input" @click="selectAll">

selectAll() {
this.$refs.input.select();
}



: https://jsfiddle.net/s7L895n7/14/





Welcome to Stack Overflow, please review: stackoverflow.com/help/how-to-answer
– Daniel
May 14 at 2:17






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Rothschild family

Cinema of Italy