Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text unselectable in IE

Tags:

html

css

select

I require one HTML element (Label) on my page to be unselectable for IE ... currently I have tried

  1. Unselectable=on
  2. onselectreturn=false;

none of which is helping me out.

For Firefox and Chrome i have set the following CSS property which are working absolutely fine ... but the problem as always with the IE.

CSS properties you have set:

-moz-user-select: -moz-none;
-khtml-user-select: none;
-webkit-user-select: none;
-o-user-select: none;
user-select: none;

is there any alternative or IE-hack?

An answer on Stack Overflow has helped me out but not for IE.

like image 394
abhijit Avatar asked Dec 12 '22 12:12

abhijit


1 Answers

<label unselectable="on"> should work for IE in the HTML. If applying it from javascript you MUST use setAttribute: labelEl.setAttribute("unselectable","on"). labelEl.unselectable = "on" does not work (tested in IE9).

Note that the "unselectable" attribute only affects text directly inside the element, not within its children - you need to set unselectable on them also, if that's the effect you want.

like image 118
Doin Avatar answered Dec 21 '22 23:12

Doin