CSS disable text selection
Don't apply these properties to the whole body. Move them to a class and apply that class to the elements you want to disable select:
.disable-select {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
How do I disable text selection with CSS or JavaScript?
<div
style="-moz-user-select: none; -webkit-user-select: none; -ms-user-select:none; user-select:none;-o-user-select:none;"
unselectable="on"
onselectstart="return false;"
onmousedown="return false;">
Blabla
</div>
CSS or Javascript to disable text selection highlighting from CTRL + A
Possible Duplicate.
If you are allowed to use jquery, here is the answer you are looking for.
65 is ascii for 'A' and 97 for 'a' if you want to account for both.
$(function(){
$(document).keydown(function(objEvent) {
if (objEvent.ctrlKey) {
if ($(objEvent.target).not('input')){
if (objEvent.keyCode == 65 || objEvent.keyCode == 97) {
objEvent.preventDefault();
}
}
}
});
});
edit: modified based on your comment to allow for input.
edit 2: if you include jQuery UI you can use disableSelection() instead of disableTextSelect()
otherwise try this.
edit 3: Sorry, disableSelection() is deprecated in jQuery 1.9 see here.. Try this simple hack instead of disableSelection(). replace objEvent.disableTextSelect();
with objEvent.preventDefault();
above.
edit 4: made it a bit cleaner.
How to disable text selection on touch press?
Use this in your CSS..
-webkit-touch-callout: none; /* Safari */
-webkit-user-select: none; /* Chrome */
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* Internet Explorer/Edge */
user-select: none;
Disable text selection dynamically per click via javascript?
You can deselect all text with javascript; add a call to RemoveSelection()
after you run the multi-select logic.
From http://help.dottoro.com/ljigixkc.php via Clear a selection in Firefox
function RemoveSelection () {
if (window.getSelection) { // all browsers, except IE before version 9
var selection = window.getSelection ();
selection.removeAllRanges ();
}
else {
if (document.selection.createRange) { // Internet Explorer
var range = document.selection.createRange ();
document.selection.empty ();
}
}
}
Related Topics
Inline Style to Act as: Hover in CSS
Fire Onmouseover Event When Element Is Disabled
How to Serve Up Images in Angular2
Frozen Table Header Inside Scrollable Div
How to Connect a Child Item in a Tree-Structure Visualization with CSS
Difference Between "Visibility:Collapse" and "Display:None"
How to Hide Text Field in HTML File Upload
Exclude Element with Fixed Positioning from Justify-Content in Flex Layout
HTML List Element: Sharing The Parent Width into Equal Parts
How to Use Webp Images and Support Safari
Hide Text, But Have It Show Up If Copied and Pasted Without JavaScript
Alternate Background Colors for List Items
Why Does "Position: Absolute; Left: 0; Right: 0; Width: Xypx; Margin: 0 Auto" Actually Center
Use Excel Vba to Click on a Button in Internet Explorer, When The Button Has No "Name" Associated
CSS Make Div Position Fixed Inside Div with Perspective Propertie
Bad Value X-Ua-Compatible for Attribute Http-Equiv on Element Meta