htmlcsscross-browsertextselection

How do I disable text selection with CSS or JavaScript?


I am making a HTML/CSS/jQuery gallery, with several pages.

I indeed have a "next" button, which is a simple link with a jQuery click listener.

The problem is that if the user click the button several times, the text of the button is selected, and then the full line of text. In my really darky design, that is really ugly and nonsensical.

So here is my question: Can you disable text selection on HTML? If not, I'll terribly miss flash and its high level of configuration on textfields...


Solution

  • <div 
     style="-webkit-user-select:none;user-select:none;" 
     unselectable="on"
     onselectstart="return false;" 
     onmousedown="return false;">
        Blabla
    </div>