Preventing text selection on web-pages

Now I’m by no means an advocate for ‘faux-DRM text protection’ but if I want a HTML element to have a click or double click event, I don’t want the text in it to be selected as well, which is where this bit of CSS comes in handy:


.prevent_selection
{
-moz-user-select: none; /* mozilla browsers */
-khtml-user-select: none; /* webkit konqueror browsers */
-webkit-user-select:none; /* webkit chrome, safari browsers */
-ms-user-select: none; /* IE10+ browsers */
}

Obviously this doesn’t work for IE9 and below, so it’s probably a good idea to use a Javascript implementation if you anticipate supporting Internet Explorer users.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s