Debian Codegraph @

www/src/content/reference/05-methods/08-htmx-process.md

raw symbols SCIP
1 ---
2 title: "htmx.process()"
3 description: "Process htmx attributes on element"
4 ---
5
6 Processes htmx attributes on the specified element and its descendants, initializing htmx functionality.
7
8 ## Syntax
9
10 ```javascript
11 htmx.process(element)
12 htmx.process(element, force)
13 ```
14
15 ## Parameters
16
17 - `element` - DOM element to process
18 - `force` - (optional) when `true`, cleans up and resets existing htmx state before processing. Use after manually mutating hx attributes on an already-initialized element
19
20 ## Usage
21
22 Use when dynamically adding HTML with htmx attributes to the page:
23
24 ```javascript
25 // Add new content to the page
26 const newContent = document.createElement('div');
27 newContent.innerHTML = '<button hx-get="/api/data">Load</button>';
28 document.body.appendChild(newContent);
29
30 // Process htmx attributes on the new content
31 htmx.process(newContent);
32 ```
33
34 Use `force` after manually mutating hx attributes on an already-initialized element:
35
36 ```javascript
37 const btn = document.querySelector('#my-btn');
38 btn.setAttribute('hx-trigger', 'keyup');
39 htmx.process(btn, true);
40 ```
41
42 ## Notes
43
44 * Automatically called by htmx after swaps
45 * Useful when manually inserting HTML with htmx attributes
46 * Processes the element and all descendants
47 * Triggers [`htmx:before:process`](/reference/events/htmx-before-process) event before processing
48 * Initializes event listeners for [`hx-get`](/reference/attributes/hx-get), [`hx-post`](/reference/attributes/hx-post), etc.
49 * Sets up boosted links and forms
50 * Processes [`hx-on`](/reference/attributes/hx-on) attributes
51 * When `force` is `true`, triggers [`htmx:before:cleanup`](/reference/events/htmx-before-cleanup) before reinitializing