question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question: Idiomatic way to "select" a tab in parent document

See original GitHub issue

How do I implement “tabs” with htmx so that labels are highlighted when the content is loaded?

I’m building an htmx starter project for some middle-schoolers. Here is a part of the main page (index.html)

<div class="tabs">
	<a hx-get="tab-a.html" hx-target="#tab-content">Tab A</a>
	<a hx-get="tab-b.html" hx-target="#tab-content">Tab B</a>
</div>
<div id="tab-content"></div>

This nicely loads content from the remote files tab-a.html and tab-b.html and swaps it into div#tab-content. However, I don’t know of a straightforward way to automatically “select” those tabs, for instance, by adding a “selected” class to each anchor. This seems like a basic feature that would be good to include, without requiring hyperscript or javascript hacks.

  1. If this already exists, can you help me understand it and I’ll add something to the docs.

  2. If this doesn’t exist, are there proposals on the table for handling this? Or, can I try proposing something simple and declarative to solve this?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
1cgcommented, Dec 7, 2020

The htmx way to do this is to include the tabs in the area replaced.

If you want to get a bit fancier and target only the content area, you can add some hyperscript or use takeClass from the javascript API: https://htmx.org/api/#takeClass

  <div onClick="htmx.takeClass(this, "activeOrWhatever")" ...>...</div>
0reactions
benpatecommented, Dec 17, 2020

I’m closing this because the PR has been merged.

Read more comments on GitHub >

github_iconTop Results From Across the Web

html - Can not view the text of the parent tab when selecting child tab ...
In Tab3, If i have selected the grand child, I could not get select view any of my parent. My code is below....
Read more >
Idioms and Idiomatic Language
Idioms and Idiomatic Language. When studying a language, one of the most challenging areas of study is the use of phrases which do...
Read more >
Idioms and Expressions - Pima County Fair
Make a note of an idiom/expression. 2. Define and explain it in understandable words (including synonyms.) 3. Give at least three sample sentences...
Read more >
IN THE LOOP - Iowa Judicial Branch
In the Loop is a collection of common idioms updated and compiled from two previous books of idioms published by the Office of...
Read more >
English Idioms and Phrases: A List with Meanings & Examples
Find common English idioms and phrases in our searchable list of expressions. Meanings and example sentences are provided for your reference.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found