I am trying to remove selection inside a contenteditable field. The code I have is this:
<h1 contenteditable>Text</h1>
<input type="text" value="Text" /><br/>
<input type="button" onclick="" value='Deselect input'>
<input type="button" onclick="$('h1').blur()" value='Deselect h1'>
And I'm auto-selecting the h1
's text via document.execCommand('selectAll', false, null);
Removing the selection for the input works, but it does not work for the h1
. How can I achieve this?
Check this fiddle
this photo shows how it behaves for me:
As you can see I just clicked deselect h1
and the text is still selected. I'm using Chrome.
an with equivalent font-size, because auto-select is exclusive for form fields I believe.
– zer00ne Jun 13 '16 at 10:07