---
name: "up.Preview.prototype.setAttrs"
area: "API"
kind: "Instance method"
parent: "up.Preview class"
url: "https://unpoly.com/api/up.Preview.prototype.setAttrs"
---
<nav aria-label="Unpoly docs">[All docs](https://unpoly.com/index.md) · [up.Preview class](https://unpoly.com/api/up.Preview.md)</nav>

# up.Preview.prototype.setAttrs([element], attributes)

Temporarily changes an element's attributes.

The element's original attributes will be restored when the preview [ends](https://unpoly.com/learn/previews.md#ending).

## Example {#example}

This preview sets a temporary `[app-loading=true]` attribute on the targeted fragment:

```js
up.preview('loading-attr', function(preview) {
  preview.setAttrs({ 'app-loading': true })
})
```

---

## Parameters {#parameters}

### [element=this.fragment] {#element}

(optional)

The element or selector to change.

If omitted, the [targeted fragment](https://unpoly.com/api/up.Preview.prototype.fragment.md) will be changed.

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

### attributes {#attributes}

(required)

An object of attribute names and values to set.

To set an empty attribute, pass an empty string value.

To remove an attribute, use a value of `null` or `undefined`.

Type: [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects)

