How this jQuery function works

Asked

Viewed 43 times

1

I’m wondering how this function is working. It has function when someone by iphone click on the link it is not in there and yes direct to link.

demo.autoclick = function() { 
    $('a').on('tap', function(e) {
        var el = $(this);
        var link = el.attr('href');
        window.location = link;
    });
} 

1 answer

3


Reading in jQuery mobile documentation:

tap Event
Description: Triggered after a Quick, complete touch Event.

That is, it is an event that works for mobile as click works for browser. Internally it listens to the touchstart and the touchend and that there was no touchmove to make sure it’s just a tap ("tap") on some element.

Then inside that callback this is the element clicked. Then the code fetches the attribute href of that element and redirect the page to that url.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.