I had to change the best answer that I accepted above, because the project I'm working on uses ES5 ( Array.from does not work), and I also had to replace e.clientX with e.touches[0].clientX , the sames goes for e .clientY.
This is what worked for me.
$(window).on('touchstart', function(e){ var selection = window.getSelection(); var tappedOnSelection = false; if(selection.rangeCount) { var args = [].slice.call(selection.getRangeAt(0).getClientRects()); tappedOnSelection = args.some(function(rect){ var top = e.touches[0].clientY; var left = e.touches[0].clientX; return left >= rect.left && left <= rect.right && top >= rect.top && top <= rect.bottom; }); } if(!tappedOnSelection){ selection.removeAllRanges(); } }); $(window).on('touchend', function(e){ e.preventDefault(); });
NOTE. Tested on Android device.
source share