> ## Documentation Index
> Fetch the complete documentation index at: https://docs.openbridge.shop/llms.txt
> Use this file to discover all available pages before exploring further.

# .count()

> Get total item count

```javascript theme={null}
openbridge.cart.count()
```

Returns the total number of items in the cart.

## Parameters

None

## Returns

`number`

Returns `0` if the cart has not been initialized.

## Examples

### Display cart count

```javascript theme={null}
const count = openbridge.cart.count()
document.querySelector('.cart-badge').textContent = count
```

### Update cart badge reactively

```javascript theme={null}
openbridge.cart.subscribe((cart) => {
    const count = cart?.totalQuantity ?? 0
    const badge = document.querySelector('.cart-badge')

    badge.textContent = count
    badge.style.display = count > 0 ? 'block' : 'none'
})
```

### Check if cart has items

```javascript theme={null}
if (openbridge.cart.count() > 0) {
    showCheckoutButton()
} else {
    showEmptyCartMessage()
}
```

### Header cart icon

```javascript theme={null}
function updateCartIcon() {
    const count = openbridge.cart.count()
    const icon = document.querySelector('.cart-icon')

    icon.setAttribute('data-count', count)
    icon.classList.toggle('has-items', count > 0)
}

// Update on any cart change
openbridge.cart.subscribe(updateCartIcon)
```

<Note>
  This returns the total quantity of all items, not the number of unique line
  items. For example, 3 t-shirts + 2 hats = count of 5.
</Note>
