I have script that toggles menu from the side:
<script>
// Closes the sidebar menu
$("#menu-close").click(function (e) {
e.preventDefault();
$("#sidebar-wrapper").toggleClass("active");
});
// Opens the sidebar menu
$("#menu-toggle").click(function (e) {
e.preventDefault();
$("#sidebar-wrapper").toggleClass("active");
});
</script>
and I use this in every section tag:
ondblclick = $("#menu-close").click()
but the problem is that when I double click somewhere it also selects text. The question is: How can I disable this double click selection on the whole page? It'd be cool if I could implement it into my actual script.
UPDATE: now I have
document.getElementById("el").ondbclick = function(ev) {
ev.preventDefault()
alert()
return false}
$("#menu-close").click(function (e) {
e.preventDefault();
$("#sidebar-wrapper").toggleClass("active");
});
// Opens the sidebar menu
$("#menu-toggle").click(function (e) {
e.preventDefault();
$("#sidebar-wrapper").toggleClass("active");
});
and id="el" on elements I don't want to be selected.. but it still doesnt work
To disable the text selection when the user double clicks on the HTML element, you can use the user-select property and set its value to none in CSS.
You'll need to call event. preventDefault() in both the down and move events in order to keep the browser from selecting text. Save this answer.
(element).querySelector('mousedown', (e) => {
e.preventDefault()
})
In Plain JavaScript...
Use these CSS-Rules on the Element:
#menu-close {
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
user-select: none;
}
Do this on every Element that should not be selected. Or just on body {
for everything.
You could also remove the double-click selection after it happened, if you don't want to disable selection everywhere:
document.getElementById("el").ondbclick = function(ev) {
ev.preventDefault()
alert()
return false
}
<div id="el"> asd</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With