0

I am using the following for a double-tap/single tap of a DOM element.

$(selector).doubletap(
     /** doubletap-dblclick callback */
     function(event){          
          var $this = $(event.currentTarget);
     },

     /** touch-click callback (touch) */
     function(event){
         doSingleClick(this)
     },
     /** doubletap-dblclick delay (default is 500 ms) */
     400
);

Another function I call from the above :

 function doSingleClick(but) {
      var $but = $(but);

      if($but.closest("#domElementId").length < 1)
          return;

      //"I have more code here to handle the if statement"
 }

The doSingleClick function never gets past the return b/c the value of $but never gets correctly defined. My assumption is that I am not passing parameters correctly. Where is my issue?

1
  • 1
    The code looks fine, asumming you wan't $but to contain a jQuery object that wraps the element that was doubletapped. Commented Dec 6, 2012 at 22:51

1 Answer 1

1

Looks like you pulled this code from here:

http://appcropolis.com/implementing-doubletap-on-iphones-and-ipads/

Looking at the code, the functions you are providing to .doubletap() are invoked on an event callback from the browser, without the benefit of the jQuery selector. The 'this' in:

 function(event){
     doSingleClick(this)
 },

is likely the Window context, not the element you are expecting. The simplest approach to fixing it is using the current element as the input:

 function(event){
     doSingleClick(event.currentTarget)
 },

which is what the doubletap/click function is already doing with the $this = $(event.currentTarget)

Hope that helps.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.