I have a list of divs that look like below:
<div id="main1">
<span class="username">Username_1</span>
white some text content inside div...
blue some text content inside div...
yellow some text content inside div...
</div>
<div id="main2">
<span class="username">Username_2</span>
another test1 text content inside div...
another test2 text content inside div...
another text test3 content inside div...
</div>
When user highlights some text inside of these divs (for example, he highlights: 'blue some text' from main1 div or 'test2 text con' from main2) -- how to get the value of username from <span class="username>{username}</span>
?
In other words, when user highlights some text from main1 div, I need to get the value: Username_1 and when he highlights some text within main2 div, I should get the value: Username_2, etc.
(if it's easier, I could add id to the span too). I can only use plain Javascript (not jQuery). Thank you.