cancel
Showing results for 
Search instead for 
Did you mean: 

How to run javascript from dynamic cms block

How to run javascript from dynamic cms block

If I add some javascript to a dynamic cms block and add the block to a cms page, the block content along with the js will be loaded via ajax and inserted to dom, but the js inside the block won't run.

Is it expected behavior and how do we fix/improve it?

3 REPLIES 3

Re: How to run javascript from dynamic cms block

@KuafuSoft when you add the js in cms block it will run when it is added in the dom.

 

Can you please share the error which you are getting?

 

Thanks

Re: How to run javascript from dynamic cms block

No error. I'm not using the regular cms block, but the dynamic cms block from M2 EE version.

The content is being injected via ajax

Re: How to run javascript from dynamic cms block

I was able to resolve that issue for myself using afterRender function in 'HTML code' Pagebuilder element

 

<div data-bind="afterRender: function(elem) {
    // Your js logic here
}"></div>