there are lots of code to get selection in a page, but i want a code to get selection inside a div, if the selection is outside of my div, the function must return empty str
You can use:
var node = window.getSelection ? window.getSelection().focusNode.parentNode: document.selection.createRange().parentElement();
to get the element in which the selection end.
Then you can determine if that element is inside your div.