Javascript examples for CSS Style Property:userSelect
The userSelect property sets or gets whether the element's text can be selected or not.
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 |
Item | Value |
---|---|
Default Value: | auto |
Return Value: | A String, representing whether the text of an element can be selected |
CSS Version | CSS3 |
Prevent text selection of a <div> element:
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo">This is a test. This is a test. This is a test.</p> <script> function myFunction() {//from www . ja v a2 s. c o m var x = document.getElementById("demo"); x.style.WebkitUserSelect = "none"; // Chrome, Safari, Opera x.style.MozUserSelect = "none"; // Firefox x.style.msUserSelect = "none"; // IE 10+ x.style.userSelect = "none"; // Standard syntax } </script> </body> </html>