The htmx.takeClass() function removes a class from all sibling elements and adds it to the target element.
Syntax
htmx.takeClass(element, className, container)
Parameters
element- Element to receive the classclassName- CSS class name to movecontainer- Optional parent element to search within (defaults to element’s parent)
Example
// Make tab active, removing from siblings htmx.takeClass(document.getElementById('tab2'), 'active'); // Within specific container let tabs = document.getElementById('tabs'); htmx.takeClass(tab, 'selected', tabs);
This is useful for implementing tab interfaces or exclusive selection patterns.