<p>Select Some of This Text</p>
<span>Now click this</span>
Is it possible to make it so that when you click on the <span>
it doesn't remove the selection of the <p>
or stores it somewhere? Maybe using the onblur
event?
<p>Select Some of This Text</p>
<span>Now click this</span>
Is it possible to make it so that when you click on the <span>
it doesn't remove the selection of the <p>
or stores it somewhere? Maybe using the onblur
event?
One method is to prevent the selection of text within the “Now click this” button, using the CSS explained in How to disable text selection highlighting?. With this CSS, clicks on the button won’t change the selection, including if there is an existing selection.
.unselectable {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
<p>Select Some of This Text</p>
<span class="unselectable">Now click this</span>