Last active
October 20, 2022 09:43
-
-
Save yuxufm/434858ae421d9d0e4ee0df41a5d566ff to your computer and use it in GitHub Desktop.
add and remove DOM using Alpine.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script defer src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"></script> | |
<div x-data="{data: []}"> | |
<div @click="data.push({ randomNumber: new Date().getTime() })">(Click Here To Add New Data)</div> | |
<template x-for="(item, index) in data" :key="index"> | |
<div> | |
<span x-text="item.randomNumber"></span> | |
<span @click="data.splice(index, 1)">Remove</span> | |
</div> | |
</template> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment