Prevents texts being selectable in Jquery

So in some situations it is needed to prevent user from selecting text in web page.

So it will play nice in some situations like drag and drop.

So it can be done using Jquery.


$('p').attr('unselectable', 'on')
.css('user-select', 'none')
.on('selectstart', false);

Code pen

Advertisements

Client Side Form validation in ASP.NET MVC

Client side form validation increases User friendliness. User doesn’t want to wait for page refresh and see form validation errors.

In ASP.NET MVC we can validate using Data Annotation. So we can use these validation to client side validation. No more huge validation codes.

We can use Jquery validation plugin comes with ASP.NET MVC. This bundle is not referenced in _layout.cshtml by default. We have to add it manually.

Watch youtube video 

Download source code

 

jQuery ajax only works in IE when the IE debugger is open

It was very annoying. Ajax request not works perfectly in IE. But when developer tool is opened ajax quires are works fine. It was very cumbersome . It happened because IE chache Ajax requests. When Developer tool opened it is always refresh from server.

I get this fixed by making cache false in ajax request.


$.ajax({
type: "GET",
url: url,
dataType: "html",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({}),
cache: false,
success: function (r) {
}
});

I think it might help you.

let run long runing task in background in javascript

So When I am in javascript development I had a long running javascript method which delays page loading. So I wanted to make it run in background to protect responsiveness of application. So I found Differed execution in Jquery.  Using differed execution we can run functions in background and do another stuffs as we want. And we can pass callback function to execute on after finishing the long running function.

Code Sample on jsfiddle