0

I have the following function working on any devices except ios 11 and don't know why, I have tried some solutions found here but it doesnt work, like : change the selector, add 'cursor:pointer' style, set an empty onclick before the function, without success.

Any idea why its this happening (or not happening),

This is the js code

    $('#buy-mobile-buttons-section').delegate('.buy-button', 'click', function(data) {
    alert('E');
    var $self = $(this);
    addToCart($(this), function(data){
        if (data > 0){
            addGMTAddToCart($self);
            var url = Routing.generate('pcc_cart_detail');
            $(location).attr("href", url);
        }
    });

});

and this is the HTML

<button type="button" data-loading-text="Añadiendo..." id="js-buy-button-mobile" class="btn btn-primary btn-lg buy GTM-addToCart buy-button"
    data-name="Asus K541UA-GO1205T Intel Core i7-7500U/8GB/1TB/15.6&quot;" 
    data-id="134853" data-price="633.49" data-brand="Asus"
    data-category="Portátiles" data-qty="1">
    <strong>Buy</strong>
    <i class="pccom-icon">]</i>

I hope you can understand it, my english is no the best arround here

Vistor
  • 149
  • 11
  • 1
    Have you tried `on()` instead of `delegate()`? – Pankaj Makwana Feb 15 '18 at 10:27
  • which version of jquery you're using because `.delegate()` has been deprecated. It was superseded by the `.on()` method since` jQuery 1.7` – Curiousdev Feb 15 '18 at 10:38
  • @PankajMakwana Yes I tried to change the selector to '#js-buy-button-mobile' and change it to on(): $(document).on('click', '#js-buy-button-mobile', function(){ //code }) But still not working – Vistor Feb 15 '18 at 11:32
  • @Curiousdev jQuery 3.2.1, But tried the on() method instead and same result – Vistor Feb 15 '18 at 11:36
  • how you have used `on` show your code so i can see what's exactly the problem is. another thing i'm not able to find button with id `buy-mobile-buttons-section` in your code above id is `js-buy-button-mobile` might be this thing you have missed – Curiousdev Feb 15 '18 at 12:20
  • @Curiousdev This is the on() version : https://plnkr.co/edit/S6vPIflGTrnQ7Z3aRazD?p=preview It works in any devices but not ios11 – Vistor Feb 15 '18 at 12:39

1 Answers1

1

Try jquery bind function.

for example:

$( "#foo" ).bind( "click", function() {
    alert( "User clicked on 'foo.'" );
});
Boris Schegolev
  • 3,601
  • 5
  • 21
  • 34
Oğuzhan Aygün
  • 137
  • 1
  • 1
  • 13
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/low-quality-posts/18830633) – Kos Feb 15 '18 at 11:32
  • sory my bad. i fixed it with a suggestion now – Oğuzhan Aygün Feb 15 '18 at 11:37
  • Tried but the result its the same, works on any device but still not working in iOS – Vistor Feb 15 '18 at 11:39
  • did you look this link https://github.com/facebook/react/issues/134 . it seems these guys have the same problem with ios – Oğuzhan Aygün Feb 15 '18 at 11:43