My JS code is:
function getSelectedText(){ if(window.getSelection){ select = window.getSelection().getRangeAt(0); var st_span = select.startContainer.parentNode.getAttribute("id").split("_")[1]; var end_span = select.endContainer.parentNode.getAttribute("id").split("_")[1]; console.log(select.endContainer); var ret_urn=[st_span,end_span]; return ret_urn } else if(document.getSelection){ return document.getSelection(); } } $(document).ready(function() { $("div#check_button button").click(function () { var loc = getSelectedText(); console.log(loc); }); });
Here is my entire html file: http://pastebin.com/acdiU623
Itβs hard to explain this, so I prepared a short film: http://www.youtube.com/watch?v=tVk4K70JO80
In a few words: when I press the left mouse button and hold it to select text / numbers and start selecting from half a letter / number, although this letter / number is not highlighted, it is added to the selection. I have to start choosing exactly. This is normal with capital letters, but with letters like i, j, or l.
This is the second example of my film. I pressed the left button 3/4 of the length of number 5, although 5 is not highlighted, it is selected.
Tested in FF and Opera.
source share