1

if i use this style for the <body>

onmousedown='return false;' onselectstart='return false;'

is it possible to give the exceptions by using javascript for inputs textareas and selects? and if yes then can u show me how?

abrabr
  • 217
  • 5
  • 14

2 Answers2

2

Actually, you can disable text selection without needing heavy-handed JavaScript event handlers. See my answer here: How to disable text selection highlighting using CSS?

Summary: use CSS and the unselectable expando in IE.

CSS:

*.unselectable {
   -moz-user-select: -moz-none;
   -khtml-user-select: none;
   -webkit-user-select: none;
   -o-user-select: none;
   user-select: none;
}

HTML:

<div id="foo" unselectable="on" class="unselectable">...</div>
Community
  • 1
  • 1
Tim Down
  • 318,141
  • 75
  • 454
  • 536
0

You need to prevent event bubbling for textboxes and selects.

You can use :input selector to select all input, textarea, select and button elements.

Something like

$(":input").bind("mousedown", function(e){
    e.stopPropagation();
});

See a working demo

rahul
  • 184,426
  • 49
  • 232
  • 263
  • but u blocked the body content by using javascript, i wanted to block by using css, and add exceptions by javascript – abrabr Jan 17 '11 at 11:46