0

I have this code, on a mobile page:

jQuery(document).ready(function($){
    $('a').on('click touchend', function(e) {
        /* Do something */
    });
});

works fine, but on mobile devices it's called both for click on links and on swipe (that is touching the link, scrolling and lifting the finger). How can I modify this to be called only on click?

I tried 'tap', 'click' and doesn't seem to work, nor I can find a good list of all the possibile events fired on mobile...

Sasha Grievus
  • 2,266
  • 5
  • 26
  • 50
  • that is the link for jquery mobile events https://api.jquerymobile.com/category/events/ – Karthik Ganesan Oct 07 '16 at 13:57
  • Yes, jquery mobile, but I can use only classical jquery. I think 'click' and 'touchend' belong to the classical version. (Indeed in my case 'tap' doesn't work, and 'touchend' is not on this list) – Sasha Grievus Oct 07 '16 at 14:03

3 Answers3

2
jQuery(document).ready(function($){
    $('a').on('vclick', function(e) {
        /* Do something */
    });
});
Diptox
  • 1,799
  • 8
  • 17
  • Since I had to look it up, it's a "virtual click" and seems to be exactly what OP is looking for https://api.jquerymobile.com/vclick/ – Brian Oct 07 '16 at 13:58
  • yep , i remember i had this problem one day – Diptox Oct 07 '16 at 13:59
  • not working :( maybe this depends by the fact the link is on a menu? I'm trying something now and I noticed that this "$('a').click(function() " is called but only the second time you click on a menu item – Sasha Grievus Oct 07 '16 at 14:02
  • yea, it's jquery mobile. No way to do this in classical jquery? – Sasha Grievus Oct 07 '16 at 14:10
0

Firstly you must recognize mobile or pc after that decide which type of event use.

example how you can recognize device here

Community
  • 1
  • 1
0

On mobile devices, it seems that the first click on a menu is taken as an hover instead of a click, so the solution in my case was

jQuery(document).ready(function($){
    $('a').hover(function(e) {
        /* Do something */
    });
});
Sasha Grievus
  • 2,266
  • 5
  • 26
  • 50