I keep getting the error “Object #<Object> has no method 'on'” in jQuery 1.8 when trying to trigger click events on dynamically loaded elements

帅比萌擦擦* 提交于 2019-12-11 11:35:00

问题


I am using jQuery 1.8 and have been getting this error on some pages when I use the .on() function. Other pages, seemingly doing the exact same thing -- attaching triggers to dynamically created elements, that I use do not generate this error:

Uncaught TypeError: Object #<Object> has no method 'on'

JS:

$(document).ready(function(){
    $(document).on("click","button.pagebutton",function() {
        $("div#pagesforreview").hide();
        jsD=Date();
        jsP=$(this).html();
        $("div#externpage").load("prexternpage.php",{d:jsD,p:jsP},function() {
            $("div#externpage").show();
            $("div#pageactions").show();
            jsNc=1;
            $("div#pagecomments").load("praddcomment.php",{d:jsD,nc:jsNc},function() {
            $("div#pagecomments").show();
            });
        });
    });
});

All dynamically generated 'pagebutton' buttons, don't trigger. And the error shows up. If I use the .live() method that is deprecated, no problems. But I prefer to use the proper new 1.8 non-deprecated method, if possible?


回答1:


I figured out that my header file was loading the jquery library (v. 1.6) from my production server not my development server (v. 1.8)... thus creating the problem. D'oh. Thanks for the comments.




回答2:


instead this $(document).ready(function(){ in the first line write this : jQuery(document).ready(function($){ it worked for me.



来源:https://stackoverflow.com/questions/12468797/i-keep-getting-the-error-object-object-has-no-method-on-in-jquery-1-8-whe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!