0

I am experiencing a weird problem. I have a jQuery function as below. The button clicks fire when you scroll the page with using a mobile phone.

The user visits the website on a mobile phone needs to scroll throughout the web page however the buttons are so sensitive when the user accidentally scrolls over the button it triggers the button event.

jQuery code:

$('body').on( 'click','.addbasket', function(e){ 
        e.preventDefault();
       alert("CLICKED");
});

Example URL:

http://meditastes.com/Kebabs-41-menu.html

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Aslan Kayardi
  • 423
  • 1
  • 4
  • 12

2 Answers2

0

You have attached a click event to BODY so the whole page is a trigger. Perhaps change it to the button element will fix this :-) $('#MyElementId').on('click',function(){//hello});

0

As said in Rune answer you can give click event to the specific id if you dont want the click to happen every time you scroll. If you are using class you can use something like this which i got from the old thread

$(".yourButtonClass").on('click', function(event){
    event.stopPropagation();
    event.stopImmediatePropagation();
    //(... rest of your JS code)
});

jQuery $(".class").click(); - multiple elements, click event once

Sz4
  • 27
  • 8