Preventing Text Selection using Javascript and Event Handlers

To prevent text selection of any element use:

in Firefox, Opera and Webkit based browsers (Chrome, Safari, etc) this can be achieved by setting a CSS property.

-webkit-user-select:none;
-moz-user-select:none;
-o-user-select: none;
user-select: none;

user-select is part of the CSS3 standard.

For IE < 9 we have two options:

Using javascript:

onselectstart="return false;"

and using the HTML attribute

unselectable="on"

Leave a Reply

You must be logged in to post a comment.