.. index:: pair: Triggers ; HTMX ! Triggers ! hx-trigger .. _htmx_triggers: ================================================================================== **hx-trigger** (Triggering Requests) ================================================================================== - https://htmx.org/docs/#triggers - :ref:`hx_trigger` Introduction ============= By default, :ref:`AJAX requests ` are triggered by the *natural* event of an element: - **input, textarea & select** are triggered on the **change** event - **form** is triggered on the **submit** event - everything else is triggered by the **click** event If you want different behavior you can use the **hx-trigger** attribute to specify which event will cause the request. Here is a div that posts to **/mouse_entered** when a mouse enters it: .. code-block:: html div hx-post="/mouse_entered" hx-trigger="mouseenter"> [Here Mouse, Mouse!] Trigger Modifiers ==================== A trigger can also have a few additional modifiers that change its behavior. For example, if you want a request to only happen once, you can use the once modifier for the trigger: .. code-block:: html
[Here Mouse, Mouse!]
Other modifiers you can use for triggers are: - changed - only issue a request if the value of the element has changed - delay: