0

Here is the html:

<body>
    <div id="screen">
        <div id="d1">blabla</div>
        <div id="d2">blabla</div>
    </div>
</body>

the "screen" div contains 100% of the screen. all the other divs with content are contained in it. Now, when i doubleclick on some empty space of the "screen" div, all of the text/images of the divs inside get selected, something which I don't want to happen. Is there any way to avoid this ?

I tried:

<div id="screen" ondblclick="return false;">

and

<div id="screen" ondblclick="unselect(this);">

where the js is :

function unselect(element) {
    if (document.selection) {
        var range = window.document.selection.createRange();
        range.collapse();
        range.select();
    } else {
        element.selectionEnd = element.selectionStart;
    }
}

but both didn't work.

EDIT: This weird behaviour seems to occur only in firefox ( opera, chrome, ie are ok ).

EDIT2 : Hunted the issue down to css. If one of the interior divs has the user-select: none then this happens. must be a firefox bug.

Tunaki
  • 132,869
  • 46
  • 340
  • 423
MirrorMirror
  • 186
  • 8
  • 36
  • 70
  • this should help http://stackoverflow.com/questions/2310734/how-to-make-html-text-unselectable – Dhiraj May 17 '12 at 13:06
  • I fixed it ( only firefox was affected ) by putting the user-select: moz-none; property in the "screen" div instead of one of the inner ones, and then enabling it for the ones i wanted it – MirrorMirror May 17 '12 at 13:17
  • 1
    so please write your own solution as answer and accept it. it may be useful for other users – Fabrizio Calderan May 17 '12 at 13:30
  • The problem occured when div with id "d1" or id "d2" had user-select:none. i removed it, and attached it to the root div ( "screen" ) – MirrorMirror May 17 '12 at 18:04
  • Please write your solution down as answer and accept it - not as comment. – acme Jun 27 '12 at 08:46
  • And as another note it is much better practice to register your events using `elem.addEventListener()` rather than DOM attributes. – ste2425 Nov 02 '15 at 08:30

0 Answers0