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?
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.
instead this
$(document).ready(function(){
in the first line write this :jQuery(document).ready(function($){
it worked for me.