JSFiddle - React, Tailwind, and code Playground
HTML
<input type='text' value='Hello World!' id='txtbox' />
<br />
<button id="btnSelect">select text</button>
<button id="btnRemove">remove selected text</button>
JavaScript
$("#btnSelect").click(function () {
document.getElementById('txtbox').setSelectionRange(6, 12);
});
$("#btnRemove").click(function () {
if (window.getSelection) {
if (window.getSelection().deleteFromDocument) {
window.getSelection().deleteFromDocument();
}
}
});