简体   繁体   中英

jquery on() selector not working on mobile browsers/dynamically created content

I am having problem with jquery on selector. When I am using

$('.class').on("click",function(){
//Code
});

its working on mobile devices but fails to select dynamically created content so I changed to

$( document ).on('click', '.class' ,function(){
//Code
});

Now that it works for dynamically created contents but is no longer supported on mobile browsers such as Opera Mini or Uc Browser How can I make it work on all conditions.

Ok finally Resolved it of My own:

add the required code in an function: and take an variable temp to store temporary boolean value

var temp=true;
function function($this){
//Code
}

$('.class').on("click",function(){
    var $this = $(this);
    function($this);
    temp=false;//making temp false to avoid re execution.
});

$( document ).on('click', '.class' ,function(){
    if(temp){
        var $this = $(this);
        function($this);
    }else{
        temp=true;//making temp true for next event.
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM