0

Here is my code:

doc.on('mousedown', '.qandacontent', function() {
    timeout_id = setTimeout(menu_toggle.bind(this), 1000);
}).bind('mouseup mouseleave', function() {
    clearTimeout(timeout_id);
});

This will show a pop up if you click on element .qandacontent and hold it for 1 sec. Now I want to make it working only if no text is selected (marked) while click-holding. Any idea how can I do that?

Derek 朕會功夫
  • 88,688
  • 41
  • 174
  • 241
Martin AJ
  • 5,689
  • 5
  • 42
  • 92
  • 1
    It would be helpful to provide a runnable snippet if you can. Or add the html so that the people who reply could provide a snippet closely matching your problem statement – Akrion Aug 02 '18 at 18:00

1 Answers1

0

You could check if there is selected text, and if so, where it is :

if ($(window.getSelection().anchorNode).attr('id') === 'something') { ... }

See:

Mtxz
  • 3,266
  • 13
  • 26