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

# up.$macro(selector, options, macro)

**This feature has been deprecated**. Use [`up.macro()`](https://unpoly.com/api/up.macro.md) with a callback that wraps the given native element in a jQuery collection.

Load [`unpoly-migrate.js`](https://unpoly.com/changes/upgrading.md) to polyfill deprecated features.

Registers a [compiler](https://unpoly.com/api/up.compiler.md) that is run before all other compilers. The compiler function is called with each matching element as a [jQuery object](https://learn.jquery.com/using-jquery-core/jquery-object/).

If you're not using jQuery, use [`up.macro()`](https://unpoly.com/api/up.macro.md) instead, which calls the macro function with a native element.

## Example {#example}

```js
up.$macro('[content-link]', function($link) {
  $link.attr({
    'up-target': '.content',
    'up-transition': 'cross-fade',
    'up-duration': '300'
  })
})
```

---

## Parameters {#parameters}

### selector {#selector}

(required)

The selector to match.

Type: string

### options {#options}

(required)

See [`options` argument for `up.compiler()`](https://unpoly.com/api/up.compiler.md#parameters).

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

### macro {#macro}

(required)

The function to call when an element matching `selector` is inserted.

Up to three arguments can be accepted:

1. The newly inserted `element` matching the selector
2. Any [data attached to the element](https://unpoly.com/learn/data.md)
3. [Meta information](https://unpoly.com/learn/enhancing-elements.md#meta) about the current render pass

The function may return a [destructor function](https://unpoly.com/learn/enhancing-elements.md#destructor) that is called before it is removed from the DOM. The destructor function is called with the compiled element.

The compiler function can be [`async`](https://unpoly.com/api/up.compiler.md#async).

Type: Function($element, [data](https://unpoly.com/learn/data.md))

