Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery mobile tapping event?

jQuery Mobile suggests to use tap events instead of click events, as click adds a delay.

So if I have:

   <a id="someID" href="#" onclick="someFunction(); return false">asd </a>

how do I change this to inline tapping event?

I could do this:

$('#someID').live('tap',function(event) { ... });

but don't want to have ID's in my scripts, so prefer to call a function inline

like image 400
Stewie Griffin Avatar asked Jan 20 '26 23:01

Stewie Griffin


2 Answers

Would you like this solution?

HTML:

<div ontap="test()">TAP ME</div>

SCRIPT:

$('[ontap]').each(function(){
    $(this).on("tap", new Function($(this).attr("ontap")));
});
like image 92
Coisox Avatar answered Jan 22 '26 12:01

Coisox


There is no "inline tapping event" like, ontap="someFunction()", as tap is a jQuery Mobile construct.

Excerpt from jQuery Mobile Source (notice the 'tap' event):

// add new event shortcuts
$.each(("touchstart touchmove touchend orientationchange throttledresize " +
        "tap taphold swipe swipeleft swiperight scrollstart scrollstop" )
        .split( " " ),
        function( i, name ) { ...

For more information:

http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.js

like image 22
Alex Avatar answered Jan 22 '26 13:01

Alex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!