Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent Highlight of Text Table

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 indicate the row is 'selected'. When the user presses shift, it is possible to select multiple rows. Sometimes this cause text to become highlighted. Is there anyway to prevent this?

like image 414
mikeycgto Avatar asked Aug 23 '09 17:08

mikeycgto


People also ask

How do I stop my text from highlighting?

Select the text that you want to remove highlighting from, or press Ctrl+A to select all of the text. Go to Home and select the arrow next to Text Highlight Color. Select No Color.

How do you not highlight text in CSS?

Use the user-select: none; CSS rule.

How do I remove highlighting in Word CSS?

Answer: Use the CSS ::selection pseudo-element By default, when you select some text in the browsers it is highlighted normally in blue color. But, you can disable this highlighting with the CSS ::selection pseudo-element.

How can I prevent text element selection with cursor drag?

Try applying user-select: none to an element and dragging over it.


2 Answers

There is a CSS3 property for that.

#yourTable {     -webkit-touch-callout: none;     -webkit-user-select: none;     -khtml-user-select: none;     -moz-user-select: none;     -ms-user-select: none;     user-select: none; } 
like image 54
Eli Grey Avatar answered Oct 02 '22 17:10

Eli Grey


If you want to have control when your users can select or not parts of you site, you can use this little jQuery plugin.

jQuery.fn.extend({          disableSelection : function() {                  return this.each(function() {                          this.onselectstart = function() { return false; };                          this.unselectable = "on";                          jQuery(this).css('user-select', 'none');                          jQuery(this).css('-o-user-select', 'none');                          jQuery(this).css('-moz-user-select', 'none');                          jQuery(this).css('-khtml-user-select', 'none');                          jQuery(this).css('-webkit-user-select', 'none');                  });          }  });  

and use it as:

// disable selection on #theDiv object $('#theDiv').disableSelection();  

Otherwise, you can just use these css attributes inside your css file as:

#theDiv  {     -webkit-user-select: none;     -khtml-user-select: none;     -moz-user-select: none;     -ms-user-select: none;     user-select: none; } 
like image 24
Cleiton Avatar answered Oct 02 '22 17:10

Cleiton