I’ve encountered an odd one the last few days and I wondered if anyone had run into the same.
Working with Sage and Woocomerce I’ve been trying to use the custom event
// Trigger event so themes can refresh other areas
$( 'body' ).trigger( 'added_to_cart', [ fragments, cart_hash, $thisbutton ] );
However if I add the a ‘on’ or ‘bind’ to this even in my main JS code it completely fails to fire.
$('body').on('added_to_cart',function(fragments, cart_hash, $thisbutton) {
console.log('Booyaka');
});
However if I add the same JS in a separate file ahead of main.js this event works just fine. However if I move this file to after main.js it again fails.
I at first thought I might have a plugin someone interfering with the process but after removing everything else it still failed to fire. Could the DOM based routing be interfering with custom events attached to the body?