Search code examples
javascriptjquerysimplecart

Trying to add link into event click in js - Simplecart


I am working on a shopping cart project, and I am using simplecart framework. I am a complete beginner at javascript.

The html:

<a class="item_add" href="javascript:;">Add to Cart</a>

Basically I would like the href to go to a checkout page for example checkout.html, but the href already has "javascript:;" value for the add the cart function, is there a way of adding to the below that it redirects or directs to checkout.html after adding to cart, I have tried a few things with no avail.

The Js:

{ selector: 'shelfItem .item_add'
, event: 'click'
, callback: function () {
var $button = simpleCart.$(this),
fields = {};
... if statements
}
// add the item
simpleCart.add(fields);
}

So after the simpleCart.add(fields); is there a way to make it go to another page.

Any help would be great!

Thanks!


Solution

  • You can use the afterAdd event for that:

    simpleCart.bind( "afterAdd" , function(){
        window.location.href = 'checkout.html'
    });