I have a table, and I'm allowing users to 'select' multiple rows. This is all handled using jQuery events and some CSS to visually and data-wise indicate the row is 'selected'. When the user presses shift, it is possible to select multiple rows. However, sometimes this cause text to become highlighted. Is there anyway to programmatically prevent this?
A:
You can try with focus() function on the selected text - the selection dissapears.
$('#someEl').focus();
gregor
2009-08-23 17:57:53
+5
A:
EDIT:
Just, write something like:
var domNode = $('#theDiv');
if (jQuery.browser.msie) {
domNode.get(0).onselectstart = function () { return false; };
} else
{
domNode.get(0).onmousedown = function(e){e.preventDefault()}
}
EDIT:
Searching on the internet, I found a blog post with a great ideia, see: http://aleembawany.com/2009/01/20/disable-selction-on-menu-items-with-this-jquery-extension/
So, you can insert into your js file:
jQuery.fn.extend({
disableSelection : function() {
this.each(function() {
this.onselectstart = function() { return false; };
this.unselectable = "on";
jQuery(this).css('-moz-user-select', 'none');
});
}
});
and use it instead:
// disable selection on #theDiv object
$('#theDiv').disableSelection();
Cleiton
2009-08-23 17:58:32
+1
A:
There is a CSS3 property for that.
#yourTable {
-moz-user-select: none;
-khtml-user-select: none;
-webkit-user-select: none;
user-select: none;
}
Eli Grey
2009-08-23 18:03:36
Too bad Internet Explorer doesn't care. Tested in 6-8.
Nathan Taylor
2009-08-23 19:28:33
A:
I simply remove the selection that is made using the shift key. This might show a little flicker though
if (event.shiftKey) {
window.getSelection().removeAllRanges()
}
ckuijjer
2009-08-24 07:40:25