# Javascript: TableOfContentsCollection.add Method

> Adds a new table of contents to the document at the current text input position.

- **Product:** TX Text Control .NET Server
- **Section:** Reference
- **Kind:** Method
- **Introduced:** 29.0
- **Path:** TX Text Control .NET Server > Reference > JavaScript API > Javascript: TableOfContentsCollection.add Method
- **522 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/tableofcontentscollection/add-method/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/tableofcontentscollection/add-method/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/tableofcontentscollection/add-method/llms-full.txt

---

### Description

Adds a new table of contents to the document at the current text input position.

### Syntax

```javascript
<void> TableOfContentsCollection.add([<TableOfContentsCollectionAddParams> parameters], [<RequestTableOfContentsCallback> callback], [<ErrorCallback> errorCallback])
```

### Parameters

| Parameter | Description |
|---|---|
| parameters | Optional. Combines the method parameters. |
| callback | Optional. Receives the added table of contents object or null if something went wrong. |
| errorCallback | Optional. Is called when the operation failed with an error. |

### Examples

The following example demonstrates `TableOfContentsCollection.add` in a practical document-editing workflow. It adds a new table of contents to the document at the current text input position.

```javascript
function onTxError(error) {
    console.error("TX Text Control error:", error.msg);
    error.handled = true;
}

function add(tableOfContentss) {
    tableOfContentss.add(
        { title: "Contents", hasLinks: true, hasPageNumbers: true, minimumStructureLevel: 1, maximumStructureLevel: 3 },
        function(toc) {
            if (!toc) {
                console.warn("No table of contents was returned.");
                return;
            }
            
            console.log("add result:", toc);
        },
        onTxError
    );
}
```

---

## Nearby

- **Previous:** [TableOfContentsCollection Object](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/tableofcontentscollection/llms-full.txt)
- **Next:** [Javascript: TableOfContentsCollection.getItem Method](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/tableofcontentscollection/getitem-method/llms-full.txt)
