0

I want to find it out selected text on div which select by mouse. I found out .select() method for select. but its not accomplish my problem.

i want to something like :

 <div id='mydiv'>Lorem Ipsum is simply dummy text of the printing.</div>

when i selected simply text using mouse selection.i found it out using jquery. or something else another selected i want to get it.

Jignesh Rajput
  • 3,538
  • 30
  • 50

1 Answers1

2

you don't need to select it. all you need to do is to add a click handler.

document.addEventListener('touchend', handleTouchEnd, false);
function handleTouchEnd(e){
   console.log(e.target.innerHTML);// returns whatever is there in the div
   console.log(e.target.textContent);// better option, as it returns text only
}
Tirtha
  • 862
  • 1
  • 12
  • 29
  • I think the OP wants to know what I want. How do I get the selected text? So if the user highlights "simply" in the innerHTML or textContent how do I get only the highlighted part? – Grant Johnson May 10 '23 at 19:08