dimanche 26 juin 2016

Cannot trigger a click on a button on mobile phones (Code and link included)

can someone explain to me why this add to cart button isn't working on mobile devices? Its not even triggering a click, I'm not getting the alert popup...

It wasn't working with "click" so i changed to "click touchstart" (i know its not an ideal solution) but i just wanted to be able to trigger the js. No success.

Its an <a> tag which triggers a jquery function, works fine on all browsers but not on mobile.

Here's the javascript code:

$('body').on('click touchstart', '.add-to-cart', function(){
  alert("click");
  //other code...
 });

The code off the button is:

<a href="#" class="add-to-cart">Add to cart<i class="fa fa-shopping-bag"></i></a>

Link to live example

Hope you guys can help me, any tip in the possible direction is valuable.

Aucun commentaire:

Enregistrer un commentaire