Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In most browsers, this can be achieved using proprietary variations on the CSS <code>user-select</code> property, <a href="http://www.w3.org/TR/2000/WD-css3-userint-20000216#user-select" rel="noreferrer">originally proposed and then abandoned in CSS3</a> and now proposed in <a href="https://drafts.csswg.org/css-ui-4/#content-selection" rel="noreferrer">CSS UI Level 4</a>:</p> <pre class="lang-css prettyprint-override"><code>*.unselectable { -moz-user-select: none; -khtml-user-select: none; -webkit-user-select: none; /* Introduced in IE 10. See http://ie.microsoft.com/testdrive/HTML5/msUserSelect/ */ -ms-user-select: none; user-select: none; } </code></pre> <p>For IE &lt; 10 and Opera &lt; 15, you will need to use the <code>unselectable</code> attribute of the element you wish to be unselectable. You can set this using an attribute in HTML:</p> <pre><code>&lt;div id="foo" unselectable="on" class="unselectable"&gt;...&lt;/div&gt; </code></pre> <p>Sadly this property isn't inherited, meaning you have to put an attribute in the start tag of every element inside the <code>&lt;div&gt;</code>. If this is a problem, you could instead use JavaScript to do this recursively for an element's descendants:</p> <pre><code>function makeUnselectable(node) { if (node.nodeType == 1) { node.setAttribute("unselectable", "on"); } var child = node.firstChild; while (child) { makeUnselectable(child); child = child.nextSibling; } } makeUnselectable(document.getElementById("foo")); </code></pre> <hr> <p><strong>Update 30 April 2014</strong>: This tree traversal needs to be re-run whenever a new element is added to the tree, but it seems from a comment by @Han that it is possible to avoid this by adding a <code>mousedown</code> event handler that sets <code>unselectable</code> on the target of the event. See <a href="http://jsbin.com/yagekiji/1" rel="noreferrer">http://jsbin.com/yagekiji/1</a> for details.</p> <hr> <p>This still doesn't cover all possibilities. While it is impossible to initiate selections in unselectable elements, in some browsers (IE and Firefox, for example) it's still impossible to prevent selections that start before and end after the unselectable element without making the whole document unselectable.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload