---
title: insertBeforeDocument
framework: tvmljs
role: symbol
role_heading: Instance Method
path: tvmljs/navigationdocument/1627340-insertbeforedocument
---

# insertBeforeDocument

Inserts a new document directly before a document currently on the stack.

## Declaration

```data
void insertBeforeDocument(
    in Document document, 
    in optional Document beforeDocument
);
```

## Parameters

- `document`: The DOM document that is to be added onto the stack.
- `beforeDocument`: A DOM document currently on the stack. The new document is placed on the stack directly after this document.

## Discussion

Discussion This function searches the stack for the first instance of the document contained in the beforeDocument parameter and inserts the document contained in the document parameter on top of it.

## See Also

### Adding Documents to the Stack

- [pushDocument](tvmljs/navigationdocument/1627361-pushdocument.md)
- [replaceDocument](tvmljs/navigationdocument/1627430-replacedocument.md)
