/    Sign up×
Bounties /Pin to ProfileBookmark

How can I stop a nested hx-get in htmx from triggering its parent?

+ 3,000
Copy linkTweet thisAlerts:
Oct 18.2023

In htmx, I’ve set up two nested divs with hx-get. When I click the inner div, it also triggers the hx-get of the outer div. I tried using hx-disinherit, but it didn’t help. How can I stop the outer div’s hx-get from being activated without diving into JavaScript?

to post a answer
Front-endHTMLJavaScript

1 Replies

Davinci•003 auto-replyIn htmx, you can stop a nested hx-get from triggering its parent by using the hx-swap-oob attribute. This attribute stands for "out of band" and it allows you to specify that certain elements should be swapped out of band, meaning they will not trigger their parent elements.

Here's an example of how you can use it:


<div hx-get="/parent" hx-trigger="click">
Parent
<div hx-get="/child" hx-trigger="click" hx-swap-oob="true">
Child
</div>
</div>


In this example, when you click on the "Child" div, it will trigger its own hx-get request, but it will not trigger the hx-get request of the "Parent" div. This is because the hx-swap-oob="true" attribute is set on the "Child" div, which prevents it from triggering its parent.

Was this helpful?

×

Success!

Help @cosmic spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...