JQuery events on iOS 5

I have a problem with jQuery 1.6.4, iOS 5 and event logging of touchstart / touchhend (as indicated in the title, obviously).

Take the following code:

<!DOCTYPE html> <html lang="fr"> <head> <meta charset="utf-8" /> <script type="text/javascript" src="mmpa/jquery-1.6.4.min.js"></script> <script type="text/javascript"> $(document).ready(function() { var $body = $('body'); $('<button>').html('test jQuery').bind('touchstart', function() { alert('touchstart'); }).appendTo($body); }); </script> </head> <body> <button ontouchstart="alert('touchstart');">test pure JS</button> </body> </html> 

The "pure JS" button shows a warning in iOS 4.3 and iOS 5, but the "jQuery" button only works on iOS 4.3. Tested on iPad / iPhone simulator, 4.3 and 5; also tested on real iPhone 4.3, iPhone 5.0 and iPad 5.0. Same reaction if I use <input type="button"> or even a simple <a> instead of <button> .

Is this a jQuery related issue, I suppose?

+6
source share
1 answer

The guy answered on the Apple dev forums: I need to bind () only after the element has been added to the DOM, for example:

 var btn = $('<a>').html('test jQuery').appendTo($body); btn.bind('touchstart', function(e) { alert('touchstart'); }); 
+8
source

Source: https://habr.com/ru/post/898836/


All Articles