skip to Main Content

Javascript – hide element on condition using AlpineJS

Using AlpineJS I have the following: <div x-data="pricing()" x-init="data = { plan: 'a' }"> <p><span x-text="calculate() + '€'"></span>per session</p> <select x-model="data.plan"> <option value="a">A</option> <option value="b">B</option> </select> </div> export default function pricing() { return { data: { plan: "", }, calculate()…

VIEW QUESTION

Javascript – Alpinejs call method when variable changes

Using Alpine.js for the first time. I have a video tag to show the camera feed, in a modal, which is initialized when the video tag is initialized using <div x-data="initTestData()" @data-transfer.window="check=$event.detail.check; runningTest=true;" class="modal fade"> <video class="w-100 rounded" id="test-video" x-init="initTest(check)">…

VIEW QUESTION

Javascript – Add an element after Alpine.js element

I have a datepicker with tailwindcss and alpinejs and it works as expected: this is my index.html file: <!doctype html> <html lang="en"> <head> <title>Datepicker</title> <script src="https://cdn.tailwindcss.com"></script> <script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/cdn.min.js"></script> <style> [x-cloak] {display: none !important;} </style> </head> <body class="flex justify-center"> <div…

VIEW QUESTION

Javascript – one code works and the other doesn't in alpine.js

@{ int MOOD = 167; } <div x-data="{ variants: [] }" x-init="fetchVariants()" x-bind:data-product-id="@MOOD"> <!-- Trigger for Modal --> <div x-text="JSON.stringify(variants)"></div> </div> <script> function fetchVariants() { const productId = document.querySelector('[x-bind\:data-product-id]').getAttribute('data-product-id'); const url = `/Home/ProductDesc?ProductId=${productId}`; fetch(url) .then(res => res.json()) .then(res => {…

VIEW QUESTION
Back To Top
Search