| 1 | --- |
| 2 | title: "htmx.find()" |
| 3 | description: "Find first matching element" |
| 4 | --- |
| 5 | |
| 6 | The `htmx.find()` function finds the first element matching a CSS selector. |
| 7 | |
| 8 | ## Syntax |
| 9 | |
| 10 | ```javascript |
| 11 | // Find from document |
| 12 | htmx.find(selector) |
| 13 | |
| 14 | // Find within element |
| 15 | htmx.find(element, selector) |
| 16 | ``` |
| 17 | |
| 18 | ## Parameters |
| 19 | |
| 20 | - `selector` - CSS selector string |
| 21 | - `element` - Optional element to search within |
| 22 | |
| 23 | ## Example |
| 24 | |
| 25 | ```javascript |
| 26 | // Find from document |
| 27 | let button = htmx.find('#myButton'); |
| 28 | |
| 29 | // Find within specific element |
| 30 | let container = htmx.find('#container'); |
| 31 | let input = htmx.find(container, 'input[type="text"]'); |
| 32 | ``` |
| 33 | |
| 34 | ## Return Value |
| 35 | |
| 36 | Returns the first matching element, or `null` if no match found. |