I have a situation where I click on the button, I need the current selection before clicking. Sample code looks like
$('div#test').on('click', 'span', function () {
sel = window.getSelection();
$('div#out p').text(sel.toString());
});
The expected behavior is shown here - http://jsfiddle.net/yvondtm/NH2DW/
Everything happens correctly when the image button is pressed. If you make a selection before clicking on the image, you will get the result - here it is just a copy of your choice.
But if you click on the text button, the selection will be lost and the result will not be as expected. Clicking on the text seems to move the cursor and therefore change the selection.
I checked the CSS-solutions such as this to turn off the selection, as I put in the violin -webkit-user-select: none;. He does what he says, but does no help — although range selection is not allowed, the carriage is still moving!
How can I solve this problem? Should I find a way to convert the text button as if it were an image?
(No problem using js or jquery or css to achieve this.)
source
share