I'm trying to learn AlpineJS with HTML. It's very easy to hide/show one div. But when I try to make 2 items in the same div (dis)appear it doesn't work for the second one. I'm assuming it's an easy fix but I can't really find the answer somewhere. Here's my code:
<!DOCTYPE html>
<html lang="en">
<head>
<script defer src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"></script>
<script src="https://cdn.tailwindcss.com"></script>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Testpage</title>
</head>
<body>
<div
x-data="{ isOpen: true }"
x-data="{ isOpen2: true }">
<button @click="isOpen = !isOpen" class="bg-slate-300 border-black border-4 mt-5">BUTTON 1</button>
<br>
<button @click="isOpen2 = !isOpen2" class="bg-slate-300 border-black border-4 mt-5 mb-5">BUTTON 2</button>
<h1 x-show="isOpen">TEXT 1</h1>
<h1 x-show="isOpen2">TEXT 2</h1>
</div>
</body>
</html>
Does anyone know how I can best make this work?