Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Alpine Examples</title>
<script src="https://cdn.jsdelivr.net/gh/alpinejs/alpine@v2.x.x/dist/alpine.min.js" defer></script>
<style>
.active { color: blue; }
.tab-wrap { border: 1px dotted grey; padding: 1rem; margin-top: 1rem; }
</style>
</head>
<body>
<div x-data="{ currentTab: 'first' }">
<button @click="currentTab = 'first'" :class="{ 'active' : currentTab === 'first'}">First</button>
<button @click="currentTab = 'second'" :class="{ 'active' : currentTab === 'second'}">Second</button>
<button @click="currentTab = 'third'" :class="{ 'active' : currentTab === 'third'}">Third</button>
<div class="tab-wrap">
<div x-show="currentTab === 'first'">
<p>First tab.</p>
</div>
<div x-show="currentTab === 'second'">
<p>Second tab.</p>
</div>
<div x-show="currentTab === 'third'">
<p>Third tab.</p>
</div>
</div>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.