---
name: "up.fragment.source"
area: "API"
kind: "JavaScript function"
parent: "up.fragment module"
url: "https://unpoly.com/api/up.fragment.source"
---
<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.source(element)

Returns the URL from which the given element was loaded.

If the given element was never directly updated, but part of a larger fragment update, the [closest](https://developer.mozilla.org/en-US/docs/Web/API/Element/closest) known source of an ancestor element is returned.

<nav aria-label="Contents">

#### Contents

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

</nav>

## Example {#example}

In the HTML below, the element `#one` was loaded from the URL `/foo`:

```html
<div id="one" up-source="/foo">
<div id="two">...</div>
</div>
```

We can now ask for the source of an element:

```javascript
up.fragment.source('#two') // returns '/foo'
```

---

## Parameters {#parameters}

### element {#element}

(required)

The element or CSS selector for which to look up the source URL.

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

---

## Return value {#return-value}

The URL from which the element was loaded.

Type: string | undefined

