Magento – Magento 2 Init script after page load

controllersjavascriptlayoutmagento2swatches

Is there any option to init (text/x-magento-init) script after page load? Example, I am working on a simple quickview feature and my controller returns my a layout – phtml file – with rendered html and script with config like this below:

<script type="text/x-magento-init">
{
    "[data-role=swatch-options]": {
        "Magento_Swatches/js/swatch-renderer": {
            "jsonConfig": ...
        }
    }
}

New content is appended to modal wrapper and new popup is initialized. Is there any option to fire (maybe some kind of event od body/document) which triggers again init process for Magento_Swatches/js/swatch-renderer script?

Best Answer

MAy be you try afterRender function to initialize function after load something you want, Take a look on following document : Js Referrence