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 whether the selection process can start in an element's content.
If the unSelectable attribute of an element is set to 'on', then the element is selectable only if the selection starts outside the contents of the element.
The difference between the unSelectable attribute and the -moz-user-select and -webkit-user-select style properties is that the -moz-user-select and -webkit-user-select style properties specify whether an element can be selected while the unSelectable attribute only specifies whether the selection process can start in an element's content or not.
Another difference is that the unSelectable attribute is not inherited while the -moz-user-select and -webkit-user-select style properties are inherited.
It means that the unSelectable attribute must be set on all non-selectable elements regardless of whether the unSelectable attribute 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.
JavaScript page for this attribute: unselectable. You can find other example(s) there.
Possible values:
String that sets 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>