0

I am trying to make text unselectale in div, i am using following code.

style="-webkit-touch-callout: none;
       -webkit-user-select: none;
       -khtml-user-select: none;
       -moz-user-select: none;
       -ms-user-select: none;
       user-select: none;" 
       unselectable="on"
       onselectstart="return false;" 

this code works perfect, but it does not allow me to click on div content and does not put cursor where i clicked on div content. I want to put cursor where i clicked. Div content also have attr contenteditable="true".

Is there any way that i can disable content selection but not mouse click.

Thanks,

Faisal Ahsan
  • 928
  • 1
  • 12
  • 22

1 Answers1

0

Try check this DEMO homie

JS

function makeUnselectable(node) {
    if (node.nodeType == 1) {
        node.setAttribute("unselectable", "on");
    }
    var child = node.firstChild;
    while (child) {
        makeUnselectable(child);
        child = child.nextSibling;
    }
}

makeUnselectable(document.getElementById("foo"));

Is this you looking for?

Fiido93
  • 1,918
  • 1
  • 15
  • 22