μ΄ μμ μμλ htmxλ₯Ό μ¬μ©νμ¬ ν λ΄μ©μ λ‘λνκ³ , μλ°μ€ν¬λ¦½νΈλ₯Ό μ¬μ©νμ¬ βνμ±β νμ μ ννλ λ°©λ²μ 보μ¬μ€λλ€. μ΄λ₯Ό ν΅ν΄ ν HTMLμ λ€μ λ λλ§νλ μμ μ μΌλΆλ₯Ό μ ν리μΌμ΄μ μλ²μμ ν΄λΌμ΄μΈνΈμ λΈλΌμ°μ λ‘ μ€νλ‘λνμ¬ μ€λ³΅μ μ€μΌ μ μμ΅λλ€.
Hypertext As The Engine Of Application State μμΉμ λ°λ₯΄λ λ μ ν΅μ μΈ μ κ·Ό λ°©μμ κ³ λ €ν΄ λ³Ό μλ μμ΅λλ€.
μλ HTMLμ ν λͺ©λ‘μ νμνλ©°, htmxλ₯Ό μΆκ°νμ¬ μλ²μμ κ° ν ν¨λμ λμ μΌλ‘ λ‘λν©λλ€.
κ°λ¨ν JavaScript μ΄λ²€νΈ νΈλ€λ¬λ take
ν¨μλ₯Ό μ¬μ©νμ¬ μ½ν
μΈ κ° DOMμ μ€μλ λ μ νλ νμ μ νν©λλ€.
<div id="tabs" hx-target="#tab-contents" role="tablist"
hx-on:htmx-after-on-load="let currentTab = document.querySelector('[aria-selected=true]');
currentTab.setAttribute('aria-selected', 'false')
currentTab.classList.remove('selected')
let newTab = event.target
newTab.setAttribute('aria-selected', 'true')
newTab.classList.add('selected')">
<button role="tab" aria-controls="tab-contents" aria-selected="true" hx-get="/tab1" class="selected">Tab 1</button>
<button role="tab" aria-controls="tab-contents" aria-selected="false" hx-get="/tab2">Tab 2</button>
<button role="tab" aria-controls="tab-contents" aria-selected="false" hx-get="/tab3">Tab 3</button>
</div>
<div id="tab-contents" role="tabpanel" hx-get="/tab1" hx-trigger="load"></div>