# Help Me Understand The Dom

**URL:** https://forums.creativeclouddeveloper.com/t/help-me-understand-the-dom/3925
**Category:** UXP Plugin API
**Created:** [November 23, 2021, 1:06pm UTC](https://forums.creativeclouddeveloper.com/t/help-me-understand-the-dom/3925 "2021-11-23T13:06:12Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![IanBarber](https://avatars.discourse-cdn.com/v4/letter/i/94ad74/32.png) [@IanBarber](https://forums.creativeclouddeveloper.com/u/IanBarber)
#### Post date: [November 23, 2021, 1:06pm UTC](https://forums.creativeclouddeveloper.com/t/help-me-understand-the-dom/3925/1 "2021-11-23T13:06:12Z")

</div>

I am starting to look closely at API 2 but need to help to get me started.

How To Duplicate A Layer:  
Looking at the docs, the following example code is supplied to duplicate a layer but simply copying and pasting doest work for me.

Can someone show me an example on how to use the following example code.

```auto
// duplicate a layer
const copyLayer = await layer.duplicate()

// extract to a new document
const exportDoc = psApp.documents[1]
const exportedLayer = await layer.duplicate(exportDoc)

```

---

<div class="post-metadata">

### Author: ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)
#### Post date: [November 23, 2021, 7:57pm UTC](https://forums.creativeclouddeveloper.com/t/help-me-understand-the-dom/3925/3 "2021-11-23T19:57:47Z")

</div>

How are you using it? This snippet alone won’t work. What is `layer` in your case?

---

<div class="post-metadata">

### Author: ![IanBarber](https://avatars.discourse-cdn.com/v4/letter/i/94ad74/32.png) [@IanBarber](https://forums.creativeclouddeveloper.com/u/IanBarber)
#### Post date: [November 23, 2021, 8:10pm UTC](https://forums.creativeclouddeveloper.com/t/help-me-understand-the-dom/3925/4 "2021-11-23T20:10:24Z")

</div>

I just copied and pasted the code direct from the docs.  
What is the best way to ref the layer

---

<div class="post-metadata">

### Author: ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)
#### Post date: [November 23, 2021, 8:58pm UTC](https://forums.creativeclouddeveloper.com/t/help-me-understand-the-dom/3925/5 "2021-11-23T20:58:52Z")

</div>

Where did you paste it? You should get a layer first. Eg.:

```auto
import {app} from "photoshop"

const layer = app.activeDocument.activeLayers[0]
const copyLayer = await layer.duplicate()

```

---

<div class="post-metadata">

### Author: ![IanBarber](https://avatars.discourse-cdn.com/v4/letter/i/94ad74/32.png) [@IanBarber](https://forums.creativeclouddeveloper.com/u/IanBarber)
#### Post date: [November 24, 2021, 5:32pm UTC](https://forums.creativeclouddeveloper.com/t/help-me-understand-the-dom/3925/6 "2021-11-24T17:32:13Z")

</div>

> [@Karmalakas](#):
>
> ```auto
> import {app} from "photoshop"
> 
> const layer = app.activeDocument.activeLayers[0]
> const copyLayer = await layer.duplicate()
> 
> ```

Thank You, that worked great
