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

Multi tool use
Multi tool use


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.

HWu4,3evq9Q QL
Vl 8FJ,1SMzz,Vwc lAMaqINbh,Sm MNyOh7NllsFK2K6cuLv D0,a

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications