userSelect Property - Javascript CSS Style Property

Javascript examples for CSS Style Property:userSelect


The userSelect property sets or gets whether the element's text can be selected or not.

Property Values

Parameter Description
auto Default.
none Prevent text selection
text The text can be selected by the user
all Text selection is made with one click instead of a double-click

Technical Details

Item Value
Default Value: auto
Return Value: A String, representing whether the text of an element can be selected
CSS VersionCSS3

Prevent text selection of a <div> element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<button onclick="myFunction()">Test</button>

<p id="demo">This is a test. This is a test. This is a test.</p>

function myFunction() {//from   www . ja v a2 s.  c  o  m
    var x = document.getElementById("demo"); = "none"; // Chrome, Safari, Opera = "none"; // Firefox = "none"; // IE 10+ = "none"; // Standard syntax


Related Tutorials