-2

There is html-code:

<input type="text">

I need to deny selecting text in <input>

Anil
  • 3,722
  • 2
  • 24
  • 49

2 Answers2

2

Since user-select: none won't work for an input, you could solve it like this:

.invisable-selection::selection { 
  background: transparent; 
}
<input class="invisable-selection" type="text" value="test" oncopy="return false">

It won't show the selection and it won't copy the value.

Simon
  • 397
  • 1
  • 3
  • 24
-2

You may try like, it's not affect any major style changes,

<input type="text" value="john" readonly>
krishna
  • 76
  • 7
  • 4
    Using your live test case, I **can** select the text with the mouse and I **can't** edit it, so it fails the requirements in the question on at least two counts. – Quentin Apr 10 '17 at 13:15