Hype Cart

Open the cart with JavaScript

Updated Nov 9, 20261 min read

On this page (3)

Send the hype:cart:open event from your store's JavaScript to open the drawer, for example from your own button. The event only works on pages where a cart is live.

Set it up

Add this to your theme's JavaScript, or to Custom JavaScript in the cart editor's Advanced panel. Replace #my-cart-button with your button's selector:

document.addEventListener('click', function (event) {  if (event.target.closest('#my-cart-button')) {    document.dispatchEvent(new CustomEvent('hype:cart:open'))  }})

Good to know

  • window.dispatchEvent works too, and the event needs no detail.
  • The event opens the drawer and changes nothing in the cart. If the drawer is already open, it stays open.
  • It works with Open automatically when items are added and Open on cart icon clicks turned off.
  • Send it after the drawer is ready, such as on a click. An event sent earlier is ignored, including one sent as soon as Custom JavaScript runs.

Related articles

Still stuck?

Ask a follow-up and we'll see it came from “Open the cart with JavaScript”.

Opens chat with your question and a link to this article.