---
name: "up.fragment.onAborted"
area: "API"
kind: "JavaScript function"
parent: "up.fragment module"
visibility: "experimental"
url: "https://unpoly.com/api/up.fragment.onAborted"
---
<nav aria-label="Unpoly docs">[All docs](https://unpoly.com/index.md) · [up.fragment module](https://unpoly.com/api/up.fragment.md)</nav>

# up.fragment.onAborted(element, callback)

**This feature is experimental**. Please [share](https://github.com/unpoly/unpoly/discussions) your experiences so we know what to keep or change.

Runs a callback when the given element _or its ancestors in the same layer_ were [aborted](https://unpoly.com/learn/aborting-requests.md).

Aborting another layer doesn't run the callback. For example, aborting the root layer doesn't affect elements in an overlay, like it doesn't abort the overlay's requests.

This utility function simplifies consumption of the [`up:fragment:aborted`](https://unpoly.com/api/up:fragment:aborted.md) event.

<nav aria-label="Contents">

#### Contents

- [Example](#example)
- [Parameters](#parameters)
- [Return value](#return-value)

</nav>

## Example {#example}

Let's say we want to [reload](https://unpoly.com/api/up.reload.md) an element after 10 seconds. If requests for that element were [aborted](https://unpoly.com/learn/aborting-requests.md) before the 10 seconds are over, we no longer want to reload:

```js
let timeout = setTimeout(() => up.reload(element), 10000)
up.fragment.onAborted(element, () => clearTimeout(timeout))
```

---

## Parameters {#parameters}

### element {#element}

(required)

The element to observe with its ancestors in the same layer.

Type: [Element](https://developer.mozilla.org/en-US/docs/Web/API/Element)

### callback {#callback}

(required)

The callback to run.

It will be called with an [`up:fragment:aborted`](https://unpoly.com/api/up:fragment:aborted.md) argument.

Type: Function(event)

---

## Return value {#return-value}

A function that unsubscribes the callback.

When the element is destroyed, the callback will be unsubscribed automatically.

Type: Function

