Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save balwantmeticulosity/771fdb8f9e78efb1d91205c02551dde8 to your computer and use it in GitHub Desktop.

Select an option

Save balwantmeticulosity/771fdb8f9e78efb1d91205c02551dde8 to your computer and use it in GitHub Desktop.
Prevent the Blue highlighting of elements in Chrome when clicking
In addition to the link provided by Floremin, which clears text selection using JavaScript to "clear" the selection, you can also use pure CSS to accomplish this. The CSS is here...
.noSelect {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
Simply add the class="noSelect" attribute to the element you wish to apply this class to. I would highly recommend giving this CSS solution a try. Nothing wrong with using the JavaScript, I just believe this could potentially be easier, and clean things up a little bit in your code.
For chrome on android -webkit-tap-highlight-color: transparent; is an additional rule you may want to experiment with for support in Android.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment