JSFiddle - React, Tailwind, and code Playground

by Joel Peterson

HTML

<div>
  Here is some text to highlight
</div>
<button id="removeHighlight">
  Click to remove highlight
</button>

JavaScript

$('#removeHighlight').on('click', function() {
  if (document.selection && document.selection.empty) {
    // for older versions of IE
    document.selection.empty();
  } else {
    // for all browsers that support the HTML Selection API
    window.getSelection().removeAllRanges();
  }
});