Javascript not working on mobile but works on desktop

后端 未结 4 974
名媛妹妹
名媛妹妹 2021-01-13 07:56

This works on a desktop browser, but not on my iOS mobile phone. I tried adding \'touchstart\' and looked at this post\'s solution to check how other\'s got it to work, but

4条回答
  •  礼貌的吻别
    2021-01-13 08:55

    This should help you. Instead of binding it to the body element, bind the event to the document.

    $(document).on('click touchstart', '.myContainer', function() {
    
          $(this).toggleClass('myContainer-unselected').toggleClass('myContainer-selected');
        });
    

    Also try changing adding the following style to myContainer class

    cursor : pointer;
    

提交回复
热议问题