1

Please refer the below link.

How to disable text selection highlighting using CSS?

The above link is useful to disable selection while dragging. code snippet.

.unselectable {
  -moz-user-select: none;
  -khtml-user-select: none;
  -webkit-user-select: none;
  user-select: none;
}

but i don't want to use css concept here. i want to set these attributes for particular element via jquery. how can i do this ?

Thanks,

Siva

Community
  • 1
  • 1
SivaRajini
  • 7,225
  • 21
  • 81
  • 128

4 Answers4

2

You can use it like this

("#yourId").css({
           -moz-user-select: none;
           -khtml-user-select: none;
           -webkit-user-select: none;
           user-select: none;
 });

It is better to use class though

Your css class:

.unselectable{
       -moz-user-select: none;
       -khtml-user-select: none;
       -webkit-user-select: none;
       user-select: none;
}

Your Jquery command

$("#yourElementId").addClass('unselectable')
Birju Shah
  • 1,220
  • 9
  • 18
0

use .css()

Get the value of a style property for the first element in the set of matched elements or set one or more CSS properties for every matched element.

$('#elementsId').css({
        -moz-user-select: none;
        -khtml-user-select: none;
        -webkit-user-select: none;
        user-select: none;
 });

or make a class and use addClass() ..cleanest way..:)

bipen
  • 36,319
  • 9
  • 49
  • 62
0

Try with .addClass():

$(yourelem).addClass('unselectable');
Jai
  • 74,255
  • 12
  • 74
  • 103
0

assuming jQuery and jQueryUI present, $("#yourDomElement").disableSelection() will do just that

lordvlad
  • 5,200
  • 1
  • 24
  • 44