Skip to content

Instantly share code, notes, and snippets.

@magdielndantas
Created August 8, 2020 00:38
Show Gist options
  • Save magdielndantas/006e37ec47a2103d3f8435655266b426 to your computer and use it in GitHub Desktop.
Save magdielndantas/006e37ec47a2103d3f8435655266b426 to your computer and use it in GitHub Desktop.
With this code, you’ll remove the outline if you use the mouse, and if you use the keyboard, you’ll enable back all the outlines.
(function(document, window){
if (!document || !window) {
return;
}
var styleText = '::-moz-focus-inner{border:0 !important;}:focus{outline: none !important;';
var unfocus_style = document.createElement('STYLE');
window.unfocus = function(){
document.getElementsByTagName('HEAD')[0].appendChild(unfocus_style);
document.addEventListener('mousedown', function(){
unfocus_style.innerHTML = styleText+'}';
});
document.addEventListener('keydown', function(){
unfocus_style.innerHTML = '';
});
};
unfocus.style = function(style){
styleText += style;
};
unfocus();
})(document, window);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment