Get started with basket.js CDN
MIT licensed
Basket.js is a lightweight library for managing shopping carts.
Tags:- script
- loading
- localStorage
Stable version
Copied!
How to start using basket.js CDN
// Import the Basket library
import basket from 'https://cdn.cdnhub.io/basket.js/0.5.2/basket.full.min.js';
// Initialize the Basket instance
const basketInstance = basket();
// Select the cart button and add a click event listener
const cartButton = document.querySelector('#cart-button');
cartButton.addEventListener('click', () => {
// Get the items from the page and add them to the Basket instance
const items = document.querySelectorAll('.item');
items.forEach((item) => {
const productId = item.dataset.productId;
const quantity = item.querySelector('.quantity input').value;
basketInstance.add(productId, quantity);
});
// Show the cart after adding items
basketInstance.show();
});
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!