I have an element with ng-dblclick='doSomthing()'
which works fine, but has the ugly side effect of selecting the text in the element too. It there any way to prevent this?
Asked
Active
Viewed 3,740 times
11

nickponline
- 25,354
- 32
- 99
- 167
-
Have you tried to move your text into a `Button` ? – WoooHaaaa Mar 06 '14 at 02:13
-
Maybe `e.preventDefault();`? I'm not that familiar with AngularJS, so I wouldn't know, but give a try - maybe it'll help. – Atutouato Mar 06 '14 at 02:32
1 Answers
16
Try to add these css rules to your class or div that you want to prevent the text selection of
.myClass {
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
-webkit-touch-callout: none;
-webkit-user-select: none;
}

njtman
- 2,160
- 1
- 19
- 32
-
1
-
this is a terrible thing to do to a website. I think a better option would be to explicitly block selection only where a user should be double clicking but not to select – pcnate Dec 20 '16 at 19:16
-
@pcnate I couldn't agree more! This is why in my example I am applying these rules to a specific css class called "myClass" and not any top level elements (div, span, button, etc). You can simply apply "myClass" or whatever you'd like the class name to be to any elements that you want to block the text selection of. – njtman Mar 19 '17 at 18:55