views:

41

answers:

3

I am trying to prevent text highlighting in Firefox for some, but not all elements on the page. Consider the following:

<div style="-moz-user-select: none;">
I cannot be highlighted
    <div  style="-moz-user-select: text;">
    I should be highlightable, but am not.
    </div>
</div>

As I understand it, using the above css rules, the text of the inner div should be highlightable. However this does not appear to work. In practice none of the text can be highlighted.

I am wondering if I am doing something wrong? If not, does anyone know of a workaround for this situation?

Thanks!

ps I should add that using the alternate...

-webkit-user-select: none;

...in the above example works just fine in webkit browsers

A: 

You may want to try onmousedown="return false" and you can change the cursor if you don't want the selection or pointer with cursor:

askon
+1  A: 

Mozilla informs the following about the none property :

The text of the element and sub-elements will appear as if they cannot be selected. Any use of Selection however will contain these elements.

Read -moz-user-select.

Babiker
That is true. However the inner -moz-user-select is still not being properly applied. In practice everything may be highlighted - but only the inner text should *appear* to be highlighted.
Travis
No matter what this property does, the inner div is a *sub-element* of the outer div.
Babiker
Right, that makes sense.
Travis
+2  A: 

Replace

<div style="-moz-user-select: none;">

with

<div style="-moz-user-select: -moz-none;">

The description of the -moz-user-select property states that -moz-none means

The text of the element and sub-elements cannot be selected, but selection can be enabled on sub-elements using -moz-user-select:text

Chi
Very nice. Thanks!
Travis