How can I detect if a user selection (highlighting with mouse) is within/a child of a certain element?
Example:
<div id="parent">
sdfsdf
<div id="container">
some
<span>content</span>
</div>
sdfsd
</div>
pseudo code:
if the entire range of window.getSelection().getRangeAt(0) is within/a child of #container
return true;
else
return false;
Update: I think this can be done by looking at each of the parent elements of the most top element in the range and see if there's a match with #container. I just need help writing this in JavaScript.