1

i read some articles, and i tried to use some codes for disable select text in website, this code running with Jquery-UI scripts

$(document).disableSelection();

but It will disable click on Selectbox, textbox and others fields and user can't do anything, it's look like readonly attribute

how can disable select text when mouse is down and doing drag without disable anything others. Thank you

MojtabaSh
  • 627
  • 1
  • 11
  • 26
  • check this out http://stackoverflow.com/questions/2700000/how-to-disable-text-selection-using-jquery – guradio Sep 16 '15 at 04:57
  • i saw this question answers, but the accepted answer don't work I think it's because my JQuery is 2.2 , and second answer doing work but will disable anything – MojtabaSh Sep 16 '15 at 05:03
  • can you make a demo in jsfiddle? – rrk Sep 16 '15 at 05:25

1 Answers1

1

You could target only the elements you don't want to be selected, like:

$('p, span, li, ...').disableSelection();

Or, why not, give a common class so you target them more accurately:

$('.noselect').disableSelection();

If second option is suitable for you, know that you don't need jQuery:

.noselect {
    cursor: default;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}
Sebastien
  • 1,014
  • 9
  • 29