I have the following jQuery excerpt:
Tselector.mouseup = function() {
var sel = getSelectionCharOffsetsWithin(document.getElementById("base"));
//...
}
Everytime when I select text in a div
tag with id=base
the above function will be triggered when releasing the mouse button. getSelectionCharOffsetsWithin(element)
is a method that parses the selection (I need that for further steps).
What I want to do now is to popup a tooltip which shows me options on what I can do with the selection. (For those of you who are familiar with iOS, it's similar to the functionality when I select text in the Web-Browser.)
The problem is that jQuery needs a DOM element to perform operations on. For example when using tipsy:
$('#foo').tipsy();
The tooltip is connected with a div
tag that has id=foo
.
When triggering the mouseup
function, I haven't such an element for my selected text, so that I am not able to connect my selection with the tooltip.
Is there any possibility to call jQuery-functions directly without a connection to a DOM element (eg. connecting the tooltip with the mouse-position)? If not, would it be possible to do a workaround with a temporary DOM element which is being created and connected on my event, but not stored in the HTML-code permanently?
Here is a fiddle to demonstrate this: http://jsfiddle.net/noplacetoh1de/bYNmb/
Thanks for any advice!