htmx 4.0 is under construction — migration guide

htmx.onLoad()

Execute callback when elements are loaded

The htmx.onLoad() function registers a callback to execute when new content is processed by htmx.

Syntax

htmx.onLoad(callback)

Parameters

  • callback - Function to call with the loaded element

Example

htmx.onLoad((element) => { console.log('New content loaded:', element); // Initialize widgets, attach listeners, etc. });

This is useful for initializing JavaScript widgets or attaching event listeners to dynamically loaded content.