DOM Methods
The following table summarizes the htmx methods related to DOM operations. These methods simplify finding and removing DOM elements.
Method | Description |
---|---|
htmx.closest | finds the closest ancestor element that matches a CSS selector |
htmx.find | finds the first element that matches a CSS selector |
htmx.findAll | finds all elements that match a CSS selector |
htmx.remove | removes an element from the DOM |
htmx.values | returns the input values present on a given element such as a form |
All but the last of these methods have DOM equivalents that are only slightly more verbose.
For example, the following sets of statements are equivalent. Assume the variable sel holds a CSS selector string and the variable el holds a DOM element.
| const match ... |
Get Server-Driven Web Apps with htmx now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.