# How to check if the document is empty or not before adding elements from the plugin?

**URL:** https://forums.creativeclouddeveloper.com/t/how-to-check-if-the-document-is-empty-or-not-before-adding-elements-from-the-plugin/6100
**Category:** UXP Plugin API
**Tags:** javascript, api-feedback
**Created:** [March 27, 2023, 2:43pm UTC](https://forums.creativeclouddeveloper.com/t/how-to-check-if-the-document-is-empty-or-not-before-adding-elements-from-the-plugin/6100 "2023-03-27T14:43:16Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Olgica](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/olgica/32/2847_2.png) [@Olgica](https://forums.creativeclouddeveloper.com/u/Olgica)
#### Post date: [March 27, 2023, 2:43pm UTC](https://forums.creativeclouddeveloper.com/t/how-to-check-if-the-document-is-empty-or-not-before-adding-elements-from-the-plugin/6100/1 "2023-03-27T14:43:16Z")

</div>

I’m having a problem adding artboards from the plugin when there are elements already in the document/pasteboard.  
For example if there is a text I can’t add an artboard from the plugin.

```auto
const addArtboard = () => {
  let btns = document.querySelectorAll("button");

  const getValues = (event) => {
    let activeBtn = event.currentTarget;
    let name = activeBtn.getAttribute("data-name");
    let fname = activeBtn.getAttribute("data-fname");
    let width = activeBtn.getAttribute("data-width");
    let height = activeBtn.getAttribute("data-height");

    editDocument({ editLabel: "add artboard" }, (selection, documentRoot) => {
      let newArtboard = new Artboard();
      newArtboard.height = JSON.parse(height);
      newArtboard.width = JSON.parse(width);
      newArtboard.fill = new Color("#ffffff");
      newArtboard.name = name;
      newArtboard.fname = fname;

      documentRoot.addChild(newArtboard);
    });
  };

  for (let i = 0; i < btns.length; i++) {
    btns[i].addEventListener("click", getValues);
  }
};

```

---

<div class="post-metadata">

### Author: ![Olgica](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/olgica/32/2847_2.png) [@Olgica](https://forums.creativeclouddeveloper.com/u/Olgica)
#### Post date: [March 28, 2023, 11:33am UTC](https://forums.creativeclouddeveloper.com/t/how-to-check-if-the-document-is-empty-or-not-before-adding-elements-from-the-plugin/6100/2 "2023-03-28T11:33:37Z")

</div>

I’m so happy I found the solution and it was so easy.  
For anyone who would have the same problem:

I just had to add the index of 0 here:

```auto
documentRoot.addChild(newArtboard, 0);

```
