Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent text highlight when click

Tags:

javascript

I have a input field with plus minus sign to raise/lower the number in it. Looks like this:

<a onclick="less()">-</a>
<input type="text" text-input">
<a onclick="more()">+</a>

How can I disable/prevent the select/highlight of the +/- text when I click to raise the numbers?

I'm looking for a solution that works cross browser. Thanks

like image 491
Rikard Avatar asked Jul 12 '13 13:07

Rikard


People also ask

How do you stop highlighting when clicking CSS?

To disable text selection highlighting in Google Chrome browser using CSS just set -user-select CSS property to none. And no prefix is required for Google Chrome and Opera Browsers.

How can I prevent text element selection with cursor drag?

You'll need to call event. preventDefault() in both the down and move events in order to keep the browser from selecting text. Save this answer.

How do I turn off double click highlighting?

To disable the text selection when the user double clicks on the HTML element, you can use the user-select property and set its value to none in CSS.


2 Answers

Depending of what versions of browsers you have to support, you can try using css property user-select to none. Here you have an example of such implementation http://css-tricks.com/almanac/properties/u/user-select/

like image 156
Juan Guerrero Avatar answered Oct 13 '22 04:10

Juan Guerrero


you can use css ::selection

::selection {
  background: none;
}
::-moz-selection {
  background: none;
}
::-webkit-selection {
  background: none;
}
like image 4
barvaz Avatar answered Oct 13 '22 03:10

barvaz