Prevent selection from Shift+Click
Prevent selection from Shift+Click
658
27-Apr-2023
Updated on 27-Apr-2023
Aryan Kumar
27-Apr-2023To 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.