Question

I'm building new web page and it's supporting ios web application. When i try to open web app, my .delegate method is not firing. It's acting like i'm clicking <a href='#'></a> . Going to top of the page and method is not firing.

What i've done so far is

$(document).delegate("a[data-what='voteThis']", "click", function (e) {
            e.preventDefault(); 
                 .
                 . 
                 .
                });

And my html code is

<a href='#' data-what='voteThis' id='vote" + id + "'> vote </a>

i've tested on Android and there is no problem with it. Also i've tested Chrome and Safari browsers on Ios, and there is no problem with them. Only on ios web app makes problem.

Was it helpful?

Solution

Unless you're using jQuery < 1.8 (which ... you shouldn't be), you should be using .on():

$(document).on('click','a[data-what="voteThis"]',function(e){
    e.preventDefault();
    ...
});

Also, please do not delegate the click event from the document ... it's horribly inefficient, you should delegate from as close of a parent as possible. Example:

$('.voteTheseContainer').on('click','a[data-what="voteThis"]',function(e){
    e.preventDefault();
    ...
});

And unless you have multiple types of elements that have the data element what, you can remore the a qualifier because it does the same thing but is faster:

$('.voteTheseContainer').on('click','[data-what="voteThis"]',function(e){
    e.preventDefault();
    ...
});

Hopefully this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top