Skip to content

Instantly share code, notes, and snippets.

@JeffreyWay
Last active September 22, 2020 16:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JeffreyWay/d3e0e5692b72c3d15d50061407028e39 to your computer and use it in GitHub Desktop.
Save JeffreyWay/d3e0e5692b72c3d15d50061407028e39 to your computer and use it in GitHub Desktop.
<!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