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.dispatchEventworks 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
Was this article helpful?
Related articles
Activate and schedule a cartA cart shows on your store only when its status is Active . Every new cart starts as a Draft . The app embed must be on: see Enable the app embed .…Nov 9, 2026Replace your theme's cartAn active cart replaces your theme's cart on your store. Four switches in the cart editor's Behavior panel control how it takes over, and all four…Nov 9, 2026Theme compatibilityHype recognizes the cart icons and cart drawers of common Shopify themes, including Dawn and Horizon. If yours isn't detected, add its CSS selector…Nov 9, 2026Manage your cartsYour carts are listed on Home . Click a cart's name to open it. Everything else is in the Cart actions menu (the three dots) on its row. To turn a…Nov 9, 2026
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.