Disable text selection except input

I have this piece of code to disable all text selection. How can I turn off all text except input? I tried $('* :not(input)').disableTextSelect();but disabled selection for everything (input is on)

$.extend($.fn.disableTextSelect = function () {
                return this.each(function () {
                    if ($.browser.mozilla) {//Firefox
                        $(this).css('MozUserSelect', 'none');
                    } else if ($.browser.msie) {//IE
                        $(this).bind('selectstart', function () { return false; });
                    } else {//Opera, etc.
                        $(this).mousedown(function () { return false; });
                    }
                });
            });
            $('* :not(input)').disableTextSelect(); 
+4
source share
4 answers

This works in IE and FF:

    jQuery(document).ready(function () {
        //Disable default text selection behavior
        toggleEnableSelectStart(false);

        //for inputs it must be possible to select text
        jQuery("input[type=text]").focusin(function () { toggleEnableSelectStart(true); });
        jQuery("input[type=text]").mouseover(function () { toggleEnableSelectStart(true); });
        jQuery("input[type=text]").focusout(function () { toggleEnableSelectStart(false); });
        jQuery("input[type=text]").mouseout(function () { toggleEnableSelectStart(false); });

    });

    function toggleEnableSelectStart(enable) {
        document.onmousedown = function (e) { return enable; };
        document.onselectstart = function (e) { return enable; }; ;
    }
+6
source
$(document).bind('mousedown selectstart', function(e) {
    return $(e.target).is('input, textarea, select, option, html');
});

Thanks to @ user2873592, who mentioned that adding htmlhere will fix, the black scroll bar cannot be shuffled.

+14
source

, . , $(), . .

.

$('body').css('MozUserSelect', '-moz-none');
$('input').css('MozUserSelect', 'text');

NOTE: the value must be "-moz-none". If "none", it cannot be changed.

I can not check IE and do not have a solution for Opera. But perhaps this will help in part.

+1
source

The selected answer does not work for me, and this answer works for me in FF: fooobar.com/questions/1381398 / ...

0
source

All Articles