views:

347

answers:

1

Does jquery or jquery-ui has such functionality? Disable text selection for given document element.

+2  A: 

There is no such function built-in.

However, you can write a simple plugiin to do it for you:

$.fn.disableSelection = function() {
    $(this).attr('unselectable', 'on')
           .css('-moz-user-select', 'none')
           .each(function() { 
               this.onselectstart = function() { return false; };
            });
};
SLaks
The JavaScript alternative works only for IE. "onselectstart" is not available for other browsers
Omar Abid
@Omar: I'm well aware of that.
SLaks
+1! I knew there was a simple way to do this. I have done this in Prototype in the past, but now that I am switching over to jQuery I was having trouble making the conversion. Thanks!
exoboy