Cookies improve the way our website works, by using this website you are agreeing to our use of cookies. For more information see our privacy policy.
OK
Sets or retrieves whether the selection process can start in an element's content.
If the unselectable property of an element is set to 'on', then the element is selectable only if the selection starts outside the contents of the element.
In Firefox, Google Chrome and Safari, use the MozUserSelect and webkitUserSelect style properties for similar functionality.
The difference between the unselectable property and the MozUserSelect and webkitUserSelect style properties is that the MozUserSelect and webkitUserSelect style properties specify whether an element can be selected while the unselectable property only specifies whether the selection process can start in an element's content or not.
Another difference is that the unselectable property is not inherited while the MozUserSelect and webkitUserSelect style properties are inherited.
It means that the unselectable property must be set on all non-selectable elements regardless of whether the unselectable property is set on the parent element of a non-selectable element or not.
For further details, see Example 2, 3 and 4.
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.
The onselectstart event bubbles up, so if the onselectstart event is canceled on an element, the selection does not start within the element and its descendant elements.
See Example 5.
String that sets or retrieves the state of selectability.
One of the following values:
off
Default. The selection process may start in the element's content.
on
The selection process cannot start in the element's content.
Default: off.
Example HTML code 1:
This example illustrates the use of the unSelectable attribute:
<divunselectable="on">
This text can be selected in Firefox, Google Chrome and Safari.
In Internet Explorer and Opera, it is selectable only if the selection starts outside.
</div><br/><br/><div>This text is selectable.</div>
<head><style>.unselectable {
-moz-user-select:none;
-webkit-user-select:none;
}
</style></head><body><divunselectable="on"class="unselectable">
This text cannot be selected in Firefox, Google Chrome and Safari.
In Internet Explorer and Opera, it is selectable only if the selection starts outside.
</div><br/><br/><div>This text is selectable.</div></body>
<head><style>.unselectable {
-moz-user-select:none;
-webkit-user-select:none;
}
</style></head><body><divunselectable="on"class="unselectable">
This text cannot be selected in Firefox, Google Chrome and Safari.
In Internet Explorer and Opera, it is selectable only if the selection starts outside.
<br/><br/><br/><div>
This text is selectable in Internet Explorer and Opera and it is not selectable in Firefox, Google Chrome and Safari.
</div><br/><br/>
This text cannot be selected in Firefox, Google Chrome and Safari.
In Internet Explorer and Opera, it is selectable only if the selection starts outside.
</div></body>
The conclusion of the previous example is that the unSelectable attribute must be used on all descendant elements to make an element unselectable:
<head><style>.unselectable {
-moz-user-select:none;
-webkit-user-select:none;
}
</style></head><body><divunselectable="on"class="unselectable">
This text cannot be selected in Firefox, Google Chrome and Safari.
In Internet Explorer and Opera, it is selectable only if the selection starts outside.
<br/><br/><br/><divunselectable="on">
This text cannot be selected in Firefox, Google Chrome and Safari.
In Internet Explorer and Opera, it is selectable only if the selection starts outside.
</div><br/><br/>
This text cannot be selected in Firefox, Google Chrome and Safari.
In Internet Explorer and Opera, it is selectable only if the selection starts outside.
</div></body>
This example is similar to the previous one, but it uses the onselectstart event to make an element unselectable in Internet Explorer:
<head><style>.unselectable {
-moz-user-select:none;
-webkit-user-select:none;
}
</style></head><body><divonselectstart="return false;"class="unselectable">
This text cannot be selected in Firefox, Google Chrome and Safari.
In Internet Explorer, it is selectable only if the selection starts outside.
In Opera, it is selectable.
<br/><br/><br/><div>
This text cannot be selected in Firefox, Google Chrome and Safari.
In Internet Explorer, it is selectable only if the selection starts outside.
In Opera, it is selectable.
</div><br/><br/>
This text cannot be selected in Firefox, Google Chrome and Safari.
In Internet Explorer, it is selectable only if the selection starts outside.
In Opera, it is selectable.
</div></body>