Update hx-trigger.md

Added an example without using JS code for better modifier understanding for basic body trigger call
This commit is contained in:
Eugene Esca 2021-03-12 23:36:58 +02:00 committed by GitHub
parent 2dae703d55
commit badc733d5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -27,6 +27,13 @@ document.body.addEventListener("myEvent", function(evt){
})
```
... or like this, if you're trying to trigger some element without using JS code:
```html
<!-- Since it bubbles up to the <body>, we must use the `from:body` modifier below -->
<div hx-trigger="myEvent from:body" hx-get="/example"></div>
```
If you want to pass details along with the event, you can move to JSON for the value of the trigger:
`HX-Trigger: {"showMessage":"Here Is A Message"}`