Disable click on div

I want to disable click on a specific <div> so that when selecting text on it, the text is not selected.

I tried writing onclick="return false;" as in this script http://jsfiddle.net/mageek/X6hqD/ , but it does not work.

How it works? (My goal is not just to turn off the selection, this is the whole click).

+4
source share
4 answers
 document.getElementById('div1').onmousedown = new function ("return false"); 
+8
source

If you want to disable only text selection, use:

 <div onselectstart='return false;'> text </div> div{ -moz-user-select: none;-webkit-user-select: none; -khtml-user-select:none;o-user-select:none; user-select: none; } 
+1
source

You can try this CSS

 <style type="text/css" media="print,screen" > .unselectable { -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } </style> <div class="unselectable"> asdasdsadsadsad<br>asdasdasd </div> <br><br> <div> qqqqqqqqqqqqqqqq<br>asdasdasd </div> 
+1
source
 <div id="div-test-id" style="width:100px;height:100px;background-color:yellow;">Lorem ipsum</div> <script type="text/javascript"> var div_click_escape=function(eventObject){ return false; }; $(function(){ $("#div-test-id").click(div_click_escape); $("#div-test-id").mousedown(div_click_escape); $("#div-test-id").mouseup(div_click_escape); } </script> 

To avoid text selection.

+1
source

All Articles