I know this shouldn\'t be that hard, but I couldn\'t find the answer on Google.
I want to execute a piece of javascript that will clear the focus from whatever eleme
None of the answers provided here are completely correct when using TypeScript, as you may not know the kind of element that is selected.
This would therefore be preferred:
if (document.activeElement instanceof HTMLElement)
document.activeElement.blur();
I would furthermore discourage using the solution provided in the accepted answer, as the resulting blurring is not part of the official spec, and could break at any moment.