In CSS, you can disable textselection with below code:
/* Disable text selection for the entire document */ body { user-select: none; }
/* Disable text selection for a specific element */ .disable-selection { user-select: none; }
In JS you can do same by following code:
// Using event listeners to prevent default behavior for text selection events function disableTextSelection() { document.addEventListener('selectstart', function (e) { e.preventDefault(); });
document.addEventListener('contextmenu', function (e) { e.preventDefault(); }); }
// Call the function to disable text selection disableTextSelection();
I hope it will helps you.
Thanks
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.
In CSS, you can disable text selection with below code:
/* Disable text selection for the entire document */
body {
user-select: none;
}
/* Disable text selection for a specific element */
.disable-selection {
user-select: none;
}
In JS you can do same by following code:
// Using event listeners to prevent default behavior for text selection events
function disableTextSelection() {
document.addEventListener('selectstart', function (e) {
e.preventDefault();
});
document.addEventListener('contextmenu', function (e) {
e.preventDefault();
});
}
// Call the function to disable text selection
disableTextSelection();
I hope it will helps you.
Thanks