Skip to content

afterRender in Knockout not working

I have one feature which is working in M2.2.1 before. But it is not working since M2.4.3
The feature mainly is to call function ‘moveElements’ when ‘opc-wrapper’ is loaded.

template/onepage.html

....
<div id="opc-wrapper" data-bind="afterRender: moveElements">
<ol class="opc" id="checkoutSteps">
<!-- ko foreach: getRegion('steps') -->
    <!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->
</ol>

checkout_index_index.xml

 <referenceBlock name="checkout.root">
        <arguments>
            <argument name="jsLayout" xsi:type="array">
                <item name="components" xsi:type="array">
                    <item name="checkout" xsi:type="array">
                        <item name="component" xsi:type="string">Custom_module/checkout</item>

checkout.js

....
return Component.extend({ 
           moveElements: function() {
                let $container = $("#opc-wrapper");
                $("#cart-discount").prependTo($container).
            }
        });
    }
);