Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I disable highlighting in html or JS?

I need to disable the highlighting of selected text on my web app. I have a good reason for doing this and know that this is generally a bad idea. But I need to do it anyway. It doesn't matter if I need to use CSS or JS to do it. What I'm mainly going for is the removal of the blue color given to highlighted elements.

like image 460
John Stimac Avatar asked Aug 03 '09 20:08

John Stimac


People also ask

How do I turn off highlighting in HTML?

To disable text selection highlighting in Google Chrome browser using CSS just set -user-select CSS property to none. And no prefix is required for Google Chrome and Opera Browsers.

How do I disable highlighter?

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 turn off highlight in CSS?

Use the user-select: none; CSS rule.

How do you disable text in HTML?

You can use the user-select property to disable text selection of an element. In web browsers, if you double-click on some text it will be selected/highlighted. This property can be used to prevent this.


1 Answers

You can use the CSS pseudo class selector ::selection and ::-moz-selection for Firefox.

For example:

::-moz-selection {     background-color: transparent;     color: #000; }  ::selection {     background-color: transparent;     color: #000; }  .myclass::-moz-selection, .myclass::selection { ... } 
like image 104
Erv Avatar answered Sep 19 '22 07:09

Erv