I'm using folloiwng jQuery library in my application. The plugin has provided two public methods as follow.
https://github.com/techlab/SmartCart/blob/master/dist/js/jquery.smartCart.js#L566
// PUBLIC FUNCTIONS
/*
* Public function to sumbit the cart
*/
submit: function () {
this._submitCart();
},
/*
* Public function to clear the cart
*/
clear: function () {
this._clearCart();
}
I'm initilizing the cart as follows.
var cart = $('#smartcart').smartCart();
I want to know how can I call the clear() method. I have tried different ways, but it gives me undefined error.
Thanks in advance.
I found the answer.
// Initialize Smart Cart
$('#smartcart').smartCart();
// Using public functions (clear and submit)
$('#smartcart').smartCart("clear");
$('#smartcart').smartCart("submit");
// Example: Clear cart when an external button click
//HTML
<button class="btn btn-danger" id="btn-clear-cart" type="button">Clear cart</button>
//JavaScript
$("#btn-clear-cart").on("click", function() {
$('#smartcart').smartCart("clear");
return true;
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.