You are here: Reference > JavaScript > client-side > style handling > properties > browser specific extensions > MozUserSelect
MozUserSelect style property | webkitUserSelect style property
MozUserSelect | ||||||
webkitUserSelect |
Specifies or retrieves whether the text of the element can be selected.
This property is the same as the user-select property in the CSS3 declaration.
In Internet Explorer and Opera, use the unselectable property for similar functionality.
In Internet Explorer, Google Chrome and Safari, there is another possibility to make an element unselectable.
If the onselectstart event is canceled, the selection process does not start.
For further details, please see the unselectable property and the onselectstart event.
Syntax:
You can find the related objects in the Supported by objects section below.
MozUserSelect: | This property is read/write. |
webkitUserSelect: | This property is read/write. |
CSS page for this property: -moz-user-select |
Possible values:
The type of this property is string.
One of the following values:
The element's contents can only be selected as a whole. | |||||||
None of the element's contents can be selected. | |||||||
The element's contents can only be selected as a whole. | |||||||
One element at a time may be selected. | |||||||
One or more elements at a time may be selected. | |||||||
Takes the value of this property from the computed style of the parent element. | |||||||
None of the element's contents can be selected. | |||||||
Default. Only the element's text content may be selected. | |||||||
The element's contents may be selected. |
Default: text.
Example HTML code 1:
This example illustrates the use of the -moz-user-select and the -webkit-user-select properties:
|
||||
<head> <style> .unselectable { -moz-user-select: none; -webkit-user-select: none; } </style> </head> <body> <div class="unselectable">The user is not able to select this text in Firefox, Google Chrome and Safari.</div> </body> |
||||
|
||||
Did you find this example helpful?
|
Example HTML code 2:
A cross-browser solution for the previous example:
|
||||
<head> <style> .unselectable { -moz-user-select: none; -webkit-user-select: none; } </style> </head> <body> <div class="unselectable" unselectable="on"> The user is not able to select this text in Firefox, Google Chrome and Safari. In Internet Explorer and Opera, it is selectable only if the selection starts outside. </div> </body> |
||||
|
||||
Did you find this example helpful?
|
Example HTML code 3:
This example uses the MozUserSelect and webkitUserSelect properties to change the selectable state of an element. For a cross-browser solution, please see the next example.
|
||||
<head> <script type="text/javascript"> function ChangeUserSelect (selectTag) { // Returns the index of the selected option var whichSelected = selectTag.selectedIndex; // Returns the text of the selected option var selectState = selectTag.options[whichSelected].text; var div = document.getElementById ("myDiv"); if ('MozUserSelect' in div.style) { div.style.MozUserSelect = selectState; } else if ('webkitUserSelect' in div.style) { div.style.webkitUserSelect = selectState; } else { alert ("Your browser doesn't support this example!"); } } </script> </head> <body> <div id="myDiv"> Select this text or <button>this button</button> or <a>this anchor element</a> and <b>change</b> the state of <i>MozUserSelect</i> with the select field. </div> <select onchange="ChangeUserSelect (this);" size="9"> <option selected="selected" />-moz-all <option />-moz-none <option />all <option />element <option />elements <option />inherit <option />none <option />text <option />toggle </select> </body> |
||||
|
||||
Did you find this example helpful?
|
Example HTML code 4:
This example shows how to change the selectable state of an element in all commonly used browsers.
|
||||
<head> <style> #mySpan { -moz-user-select:none; -webkit-user-select:none; } </style> <script type="text/javascript"> function ToggleSelState () { var span = document.getElementById ("mySpan"); if ('unselectable' in span) { // Internet Explorer, Opera span.unselectable = !span.unselectable; } else { if (window.getComputedStyle) { var style = window.getComputedStyle (span, null); if ('MozUserSelect' in style) { // Firefox span.style.MozUserSelect = (style.MozUserSelect == "none") ? "text" : "none"; } else { if ('webkitUserSelect' in style) { // Google Chrome and Safari span.style.webkitUserSelect = (style.webkitUserSelect == "none") ? "text" : "none"; } else { alert ("Your browser doesn't support this example!"); } } } else { alert ("Your browser doesn't support this example!"); } } } </script> </head> <body> <span id="mySpan" unselectable="on">Select this text.</span> <br /><br /><br /> <button onclick="ToggleSelState ();">Change selectable state!</button> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
CSSStyleDeclaration, htmlElement.style
HTML elements:
a, abbr, acronym, address, b, bdo, big, blink, blockquote, body, caption, center, cite, code, dd, del, dfn, dir, div, dl, dt, em, fieldset, font, form, h1, h2, h3, h4, h5, h6, html, i, ins, isindex, kbd, label, legend, li, marquee, menu, ol, optgroup, option, p, pre, q, s, samp, small, span, strike, strong, sub, sup, table, td, textarea, th, tr, tt, u, ul, var, xmp
Related pages:
External links:
-moz-user-select (Mozilla Developer Center)
-webkit-user-select (Safari Reference Library)
user-select (W3C)
-webkit-user-select (Safari Reference Library)
user-select (W3C)
User Contributed Comments