Disabled select element jquery example.

11-Apr-2023

.

Admin

Hii guys,

In this artical, i will give you disable select using jQuery.If You are looking for a simple way to disable select for any html element then here you will find the best solution to disable select on page.

There are some reasons why you will select text disable.

Example 1


It may be you want to show your own menu html page select text disable on a , useing the jQuery-ui bind() method.

<!DOCTYPE html>

<html>

<head>

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>

<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

</head>

<body>

<h3>Select text disable on this page.</h3>

<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod

tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,

quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo

consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse

cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non

proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>

<script>

$( function() {

$('body').attr('unselectable','on')

.css({'-moz-user-select':'-moz-none',

'-moz-user-select':'none',

'-o-user-select':'none',

'-khtml-user-select':'none', /* you could also put this in a class */

'-webkit-user-select':'none',/* and add the CSS class here instead */

'-ms-user-select':'none',

'user-select':'none'

}).bind('selectstart', function(){ return false; });

} );

</script>

</script>

</body>

</html>

Example 2

It may be you want to show your own menu html page select text disable on a useing the jQuery-ui onmousedown() and onselectstart() method.

<!DOCTYPE html>

<html>

<head>

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>

</head>

<body onmousedown = 'return false' onselectstart = 'return false'>

<h3>Select text disable on this page.</h3>

<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod

tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,

quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo

consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse

cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non

proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>

</script>

</body>

</html>

Example 3

It may be you want to show your own menu html page select text disable on a useing the disableSelection() method.

<!DOCTYPE html>

<html>

<head>

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>

<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

</head>

<body>

<h3>Select text disable on this page.</h3>

<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod

tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,

quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo

consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse

cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non

proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>

<script>

$( function() {

$('body').disableSelection();

} );

</script>

</body>

</html>

It will help you...

#Jquery