I have a div container placed inside an html page. There is some text placed inside it. Now, I want the text (any amount) selected by the user to be displayed in another div container on the same page.
<div id="d1"> Some Random text, Some Random text Some Random text, Some Random text</div>
<div id="d2"></div>
I am stuck on how to extract the text from the d1
container. I have tried using window.getSelection()
and related methods. The irony is that it is applied on the entire document. How to go about it?
P.S-JSFiddle demo would be helpful.