I have referred Getting selected text position and Get selected text position and place an element next to it but it's not working in my case.
My case is I want to get the start and end position of highlighted text and my code is
// TO GET THE HIGHLIGHTED TEXT VALUE
const handleMouseUp = () => {
const selectedTextValue = window.getSelection().toString()
console.log(selectedTextValue)
}
But when I use the below code then
// TO GET THE HIGHLIGHTED TEXT VALUE
const handleMouseUp = () => {
const selectedTextValue = window.getSelection().toString()
const oRange = selectedTextValue.getRangeAt(0); //get the text range: ;
const oRect = oRange.getBoundingClientRect();
console.log(oRect)
}
I get the error Property 'getRangeAt' does not exist on type 'string'.
Where am I going wrong ? Please help !