To prevent selection of text when using Shift+Click, you can use JavaScript to disable text selection on the
mousedown event when the Shift key is pressed. Here's an example:
// Select the element you want to make unselectable
var element = document.getElementById("my-element");
// Add an event listener to the element
element.addEventListener("mousedown", function(event) {
// Check if the Shift key is pressed
if (event.shiftKey) {
// Disable text selection
event.preventDefault();
}
});
In this example, we're checking if the Shift key is pressed when the user clicks on the element using the
shiftKey property of the event object. If the Shift key is pressed, we're calling the
preventDefault() method to prevent text selection.
Note that this technique only prevents text selection when using Shift+Click. Users can still select the text using other methods, such as dragging the mouse over the text or using the keyboard.
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
To prevent selection of text when using Shift+Click, you can use JavaScript to disable text selection on the mousedown event when the Shift key is pressed. Here's an example:
In this example, we're checking if the Shift key is pressed when the user clicks on the element using the shiftKey property of the event object. If the Shift key is pressed, we're calling the preventDefault() method to prevent text selection.
Note that this technique only prevents text selection when using Shift+Click. Users can still select the text using other methods, such as dragging the mouse over the text or using the keyboard.