HTML with JavaScript this is one method on app.js addItemToCart () { // hint: yo
ID: 3851281 • Letter: H
Question
HTML with JavaScript
this is one method on app.js
addItemToCart () {
// hint: you can use `dataset` to access data attributes
// See passing data from HTML to JavaScript from course note
let cartItems = this.store.cartItems || [];
// TODO: replace with actual item
console.log(this.root.data);
cartItems.push({
name: 'test'
});
console.log(cartItems);
this.store.cartItems = cartItems;
}
-------------------------------
and it ask me to update with actual
my button on HTML is this
td><button class = "checkout-button" data-name = "pasta" data-price = "16.00">Order Pasta</button></td>
so what should i change on js?
Explanation / Answer
The script must look like this for things to work properly:
ShopCart.js
$(document).on('click', '.net', function(o) {
o.preventDefault();
var $this = $(this);
var $shop = $('#shop');
var items = $this.data('id');
// If item is in shop already then remove
if ($this.data('in-stock')==='yes'
&& $shop.find('li[data-id="' + items + '"]').length > 0) {
// Script to remove item from shop
return
}
// else add to shop
$this.data('in-stock', 'yes');
var send_to_cart = $('li').data('id', items).html($this.html());
$shop.append(send_to_cart);
});
Hence, this is the way the script should work to add data to the shopping cart.
Please rate the answer if it helped.....Thankyou
Hope it helps....
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.