<body>
<input type="text" id="test" value="ajanuw">
<script>
document.querySelector('#test').addEventListener('mouseup', (e)=>{
var activeElement = document.activeElement;
console.log( activeElement.selectionStart, activeElement.selectionEnd);
var start = activeElement.selectionStart,
end = activeElement.selectionEnd;
console.log( e.target.value.substring(start, end));
}, false)
</script>
</body>