bigcommerce

JavaScript not executing after paginating through products in BigCommerce Cornerstone theme


I have a small bit of JavaScript which is not firing after navigating through paged results in a BigCommerce Cornerstone theme (using Cornerstone 6.7.0).

I've added the following to the onReady() method in the category.js file:

$('.mm-button').on('click', (e) => alert("clicked")); 

This will execute on an initial page load but not after clicking on pagination links (next, prev, page number).

I've also tried moving the JavaScript into its own .js file and including it into the theme. The same behavior happens where it executes on the initial page load but not after paging through records.


Solution

  • The issue here is that pagination actually works by editing the content via JavaScript, so it does not run the category onReady() again. You could add the JavaScript into the page content function, but a simpler method is to simply delegate the click event. Change your code like this:

    $('body').on('click', '.mm-button' (e) => alert("clicked"));