How to Reinitialize Interactions After Replacing a Section via AJAX?

Hello everyone,

I’m using Bricks 2.0.1 (Bricks 2.0.1 Changelog – Bricks)) and have developed a custom script that updates only the comments section via AJAX. After replacing the HTML of this section, I need the Bricks Interactions and Pop-ups to function again (especially the button that opens a popup). I’ve tried several approaches without success.

The current flow is:

  • Capture the form submission → send via fetch() to wp-admin/admin-ajax.php.
  • Receive the HTML output and execute:

javascript
current.replaceWith(freshHtml);

Then, attempt to reinitialize:

// I’ve tested all these variations
document.dispatchEvent(new CustomEvent(‘bricks/ajax/nodes_added’, { detail: { nodes: freshHtml } }));
bricksInteractions?.();
bricksFrontend?.interactions?.init(document);
bricksPopup?.init?.(document);
bricksPopup?.createPopups?.(document);

The HTML is injected correctly, but the icon that should open the popup stops responding.

What I’ve checked/observed:

• If I reload the entire page, the popup opens normally, so it’s not a markup issue.

window.bricksData.interactions contains my Interactions; however, calling bricksInteractions() after the AJAX doesn’t reapply them.

• Inspecting the minified JS, I saw that Bricks calls bricksInteractions() within DOMContentLoaded and also listens for bricks/ajax/nodes_added, but apparently, neither reprocesses my new block.

Specific questions:

  • Is there a public function (or internal event) that Bricks calls to “register” Interactions on a newly added node?
  1. What would be the correct sequence of calls to ensure both Interactions and Pop-ups are recreated?
  • Is there any attribute/flag I need to remove for Bricks to recognize the element as “new”?

Any insights, code snippets, or documentation links would be greatly appreciated.

Thank you in advance!

can’t right now dive deep into code, but try this function:
bricksRunAllFunctions() after the ajax event. if the HTML-Element hast the apporpriat data-attributes it should work.

1 Like