Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent selecting text on double click?

#btnLeft{
    width:40px;
    padding:2px 5px 2px 5px;
    background-color: #20a0a0;
    border: thin solid #099;
    border-radius:7px;
    text-align:center;
    font-family:"Futura Md BT";
    font-size:large;
    color:#FFF;
}

This is a css button.
When user accidentally makes double click instead of single one, text inside the button becomes selected, i.e. - changes its background color.
How to prevent this selecting on double click ?

like image 775
Alegro Avatar asked Dec 04 '12 17:12

Alegro


People also ask

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.

How do I disable something in CSS?

You can't disable anything with CSS, that's a functional-issue. CSS is meant for design-issues. You could give the impression of a textbox being disabled, by setting washed-out colors on it. Keep in mind that disabled inputs won't pass their values through when you post data back to the server.


2 Answers

try little jquery

 $(element).mousedown(function(){ return false; })

with css try

-webkit-user-select: none;
-moz-user-select: none;
-khtml-user-select: none;
-ms-user-select: none;
like image 144
NullPoiиteя Avatar answered Oct 28 '22 07:10

NullPoiиteя


If you use a <button> or <a> tag and include an href attribute then the behaviour should be mitigated. And its more semantic :)

like image 40
Gazza Avatar answered Oct 28 '22 07:10

Gazza