I have code that select text when user click the p tag but I don't want to do that when user select the text inside. Is it possible to detect click but without drag?
I have simple code like this:
$('.conteiner').on('click', 'p.xxx', function() {
   $(this).selection();
});
But click is executed even if I drag between mousedown and mouseup. The selection is a plugin that select text using getSelection or Range.
Similar to this: Can you detect "dragging" in jQuery?
You can use mousedown and mouseup to detect whether there was a drag.
 $(function() {
    var isDragging = false;
    $(".conteiner")
    .mousedown(function() {
        $(window).mousemove(function() {
            isDragging = true;
            $(window).unbind("mousemove");
        });
    })
    .mouseup(function() {
        var wasDragging = isDragging;
        isDragging = false;
        $(window).unbind("mousemove");
        if (!wasDragging) {
            $(this).selection();
        }
    });
  });
Here is the plunker demo: http://embed.plnkr.co/Y7mrOP/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With