How to disable text selection on html web page using JQuery & CSS?

How to disable text selection on html web page using JQuery & CSS?

In this post we will give you information about How to disable text selection on html web page using JQuery & CSS?. Hear we will give you detail about How to disable text selection on html web page using JQuery & CSS?And how to use it also give you demo for it if it is necessary.

Here, we will discuss how to disable text selection on website page using jquery. we can also disable content selection using css and jquery. here i will give you more examples to disable text selection on a web page using jquery and css.

I given first i will give you simple example of disable text selection on website jquery using css property. you need to just add some css on your body tag as you can see on bellow example example code. you can simply copy and check that.

Example 1 – Disable text selection on web page in HTML using CSS

<!DOCTYPE html>

<html>

<head>

<title>disable selection of text on web page - ItSolutionStuff.com</title>

<style type="text/css">

body{

user-select: none; /* supported by Chrome and Opera */

-webkit-user-select: none; /* Safari */

-khtml-user-select: none; /* Konqueror HTML */

-moz-user-select: none; /* Firefox */

-ms-user-select: none; /* Internet Explorer/Edge */

}

</style>

</head>

<body>

<h3>How to disable text selection on html web page using JQuery?</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>

</body>

</html>

Second example i will give you simple core jquery. we can create our own disableSelection() jqurey function and we will use it on body tag. so you can also check bellow code for that.

Example 2 – disable selection of text on web page using JQuery

<!DOCTYPE html>

<html>

<head>

<title>disable selection of text on web page - ItSolutionStuff.com</title>

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

</head>

<body>

<h3>How to disable text selection on html web page using JQuery?</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 type="text/javascript">

(function($){

$.fn.disableSelection = function() {

return this

.attr('unselectable', 'on')

.css('user-select', 'none')

.on('selectstart', false);

};

})(jQuery);

$('body').disableSelection();

</script>

</body>

</html>

In Third Example, we will use jquery ui. as we know jquery ui provide several function that amazing. in this example we will use disableSelection() for disable text selection on website jquery, so let’s see bellow code:

Example 3 – disable text selection on website jquery ui

Also see:jQuery disable submit button on click to prevent multiple form submits

<!DOCTYPE html>

<html>

<head>

<title>disable text selection on website jquery - ItSolutionStuff.com</title>

<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>How to disable text selection on html web page using JQuery?</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 type="text/javascript">

$('body').disableSelection();

</script>

</body>

</html>

I hope it can help you…

Hope this code and post will helped you for implement How to disable text selection on html web page using JQuery & CSS?. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  33  =  35

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US