Magento2 – Trigger Content Update Event in JavaScript

javascriptmagento2

I saw a lot of events trigger('contentUpdated'). For example: vendor/magento/module-catalog/view/frontend/web/js/catalog-add-to-cart.js. My question is:

  • Where is the function contentUpdated?
  • Can anyone give me a brief description about it?

Best Answer

contentUpdated is not a function, it is an event (similar to the load or click events).

This event is listened in lib/web/mage/mage.js :

$('body').on('contentUpdated', function () {
    if (mage) {
        mage.apply();
    }
});

It basically reinit the components inside a dynamic group of update elements.

Related Topic