Q:

Javascript Trigger "right arrow" key event - Force Label Deselection

I want to trigger a keyboard event to press "right arrow" key. The purpose is to cancel the highlight.
I used the code below to insert a hyper link into the editor content.
var range = document.getSelection().getRangeAt(0);
var nnode = document.createElement("a");
range.surroundContents(nnode);
nnode.innerHTML = url;
nnode.setAttribute(url);
nnode.focus();

It is highlight by default. I want to trigger an "right arrow" key in order to cancel the highlight and move the cursor to the right. I did many searchs, I tried the most of solutions, but I still get one works. My environment is IE 11.
Can I get some help?
Thanks!

A:

So.. here are the resources you're asking for, but I have a solution for your highlighting problem which is none of these.
Resources:
How to trigger click on page load?
Detecting arrow key presses in JavaScript
Trigger an UP or DOWN ARROW key event through javascript

The actual solution uses JQuery & this resource: JavaScript Set Window selection

$("document").ready(function() {
   window.getSelection().removeAllRanges();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="myDiv">
I am some text!
</div>

See the JSFiddle: JSFiddle

