let me first explain my issue.
I'm working on a webpage which prints a long text with data retrieved from a db. Each word of the text has is own id (which in turn is a primary key).
I'm wondering if it is possible to select portion of text with mouse and contextually collect all the ids of this selection.
At present, I tried with a very simple click function:
var idList = []
$('.tags').click(function() {
var feature = [this.id, this.text];
idList.push(feature);
info.innerHTML = idList;
});
However, it is not very handy becouse of users must click on every word to collect data. At the same time I tried withwindow.getSelection() and the way it works is perfect for my needs, but as far I can understand it returns only a string with all selected words and does not their attributes.
EDIT, Oct 10 2017
This question may already have an answer here:
Get span Id's of selected text using getSelected()
Yes, this is true indeed, but the solution proposed are fairly different. I find very interesting this solution because it is a true selection method and it seems to work pretty well on multi line texts. At the same time the solution proposed here by Taurus is very interesting: as far as I can understand it does not fit well for multline selelctions (example), but anyway it offers the opportunity of selecting non-contiguous portions of text, as well as to deselect a single selection, which are both very important for my small project.