hx-select
Управляет тем, какая часть ответа вставляется
Атрибут hx-select выбирает содержимое ответа для замены.
Задайте его равным CSS-селектору, который будет применён к ответу:
<button hx-get="/info" hx-target="#result" hx-select="#info-detail"> Get Info </button> <div id="result"> <!-- Selected content goes here --> </div>
Сервер может вернуть полную страницу:
<header>This is ignored</header> <!-- This... --> <section id="info-detail"> <h2>Details</h2> <p>Only this section is selected.</p> </section> <!-- ...is selected --> <footer>This is also ignored</footer>
htmx заменяет только соответствующий элемент в #result:
<div id="result">
<!-- Only the selected element is inserted -->
<section id="info-detail">
<h2>Details</h2>
<p>Only this section is selected.</p>
</section>
</div> См. также
Licensed under the Zero-Clause BSD License.
https://four.htmx.org/reference/attributes/hx-select/