Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

Uncaught TypeError: jQuery(...).on is not a function

roshanc44331495
Level 4
Level 4

Hi,

Getting "Uncaught TypeError: jQuery(...).on is not a function" error while testing the custom tracking and this is happening only on one page rest it's working fine, as we can see in the below screenshot.

1536000_pastedImage_2.png

Error line:

1535999_pastedImage_1.png

Function:

function bindKudoEvent(){
jQuery('.lia-button-image-kudos-kudoed a.kudos-link').on('click',function(e){
var isAcceptedSol = jQuery(this).parents('.lia-message-view-display').hasClass('lia-accepted-solution');
trackClickTkb(0,"kudo count",isAcceptedSol)
setTimeout(function(){ bindKudoEvent() }, 3500);
});
jQuery('.lia-button-image-kudos-not-kudoed a.kudos-link').on('click',function(e){
var isAcceptedSol = jQuery(this).parents('.lia-message-view-display').hasClass('lia-accepted-solution');
trackClickTkb(1,"kudo count", isAcceptedSol)
setTimeout(function(){ bindKudoEvent() }, 3500);
});
}

bindKudoEvent();

Thanks!

1 Accepted Solution
StewSchilling
Correct answer by
Community Advisor
Community Advisor

If jQuery is loading asynchronously you could have a race condition between DTM and the loading of jQuery.

I don't think that you need to do event handling this way.  I'd use event rules within DTM.  That would free you from this issue.

In cases where I do need to work outside of DTM, I try to use native Javascript to avoid dependencies on libraries like jQuery.

View solution in original post

3 Replies
katherinew33547
Level 1
Level 1

Does jQuery exist on the page at the point that your function is executed? If not, then that would cause this error.

roshanc44331495
Level 4
Level 4

jQuery exist on the page I got this error on page load mostly.

StewSchilling
Correct answer by
Community Advisor
Community Advisor

If jQuery is loading asynchronously you could have a race condition between DTM and the loading of jQuery.

I don't think that you need to do event handling this way.  I'd use event rules within DTM.  That would free you from this issue.

In cases where I do need to work outside of DTM, I try to use native Javascript to avoid dependencies on libraries like jQuery.

View solution in original post