Skip to content

Instantly share code, notes, and snippets.

@azu
Created December 9, 2011 08:10

Revisions

  1. azu created this gist Dec 9, 2011.
    19 changes: 19 additions & 0 deletions jquery.disableSelection.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    (function ($) {
    $.fn.disableSelection = function () {
    return this.each(function () {
    $(this).attr('unselectable', 'on')
    .css({'-moz-user-select':'none',
    '-o-user-select':'none',
    '-khtml-user-select':'none',
    '-webkit-user-select':'none',
    '-ms-user-select':'none',
    'user-select':'none'})
    .each(function () {
    $(this).attr('unselectable', 'on')
    .bind('selectstart', function () {
    return false;
    });
    });
    });
    };
    })(jQuery);