---
title: "Navigation with Cursor in Node.js"
---


While working with a document, even if it is a short or long one, you will need to navigate through your document. Navigation with a virtual cursor represents the ability to navigate between different nodes in a document.

Within a short document, moving around in a document is simple as you can move the insertion point even by using the keyboard's arrow keys or by clicking the mouse to locate the insertion point wherever you want. But once you have a large document that has many pages, these basic techniques will be insufficient.

This article explains how to move around in a document and navigate with a virtual cursor to different parts of it.

## Detecting Current Cursor Position

Before starting the process of navigating through your document, you will need to get the node that is currently selected. You can get the exact position of the cursor at a selected node by using the [currentNode](https://reference.aspose.com/words/nodejs-net/aspose.words/documentbuilder/currentNode/) property. In addition, instead of getting the current node, you can get the currently selected paragraph or the currently selected section by using the [currentParagraph](https://reference.aspose.com/words/nodejs-net/aspose.words/documentbuilder/currentParagraph/) and [currentSection](https://reference.aspose.com/words/nodejs-net/aspose.words/documentbuilder/currentSection/) properties.

Any insert operations you perform using the [DocumentBuilder](https://reference.aspose.com/words/nodejs-net/aspose.words/documentbuilder/) will be inserted before the [currentNode](https://reference.aspose.com/words/nodejs-net/aspose.words/documentbuilder/currentNode/). When the current paragraph is empty or the cursor is positioned just before the end of the paragraph, the [currentNode](https://reference.aspose.com/words/nodejs-net/aspose.words/documentbuilder/currentNode/) returns None.

## Navigating Methods in a Document

When you are editing text, it is important to know how to navigate your document and where exactly to move in it. Aspose.Words allows you to move around in a document and navigate to its different sections and parts – this is similar to the functionality of the Navigation Pane in Microsoft Word to go to a page or heading in a Word document without scrolling.

The main method is to be able to move the cursor position to a specific node in your document, you can achieve this by using the [moveTo](https://reference.aspose.com/words/nodejs-net/aspose.words/documentbuilder/moveTo/) method.

The following code example shows how to move the [DocumentBuilder](https://reference.aspose.com/words/nodejs-net/aspose.words/documentbuilder/) to different nodes in a document:

{{< gist "aspose-words-gists" "811254d9cf25578ceaa32a1d990f70fa" "move-to-node.js" >}}

But besides the basic [moveTo](https://reference.aspose.com/words/nodejs-net/aspose.words/documentbuilder/moveTo/) method, there are more specific ones.

### Navigate to Beginning or End of a Document

You can go to the beginning or the end of your document using the [moveToDocumentStart](https://reference.aspose.com/words/nodejs-net/aspose.words/documentbuilder/moveToDocumentStart/) and [moveToDocumentEnd](https://reference.aspose.com/words/nodejs-net/aspose.words/documentbuilder/moveToDocumentEnd/) methods.

The following code example shows how to move the cursor position to the beginning or the end of a document:

{{< gist "aspose-words-gists" "811254d9cf25578ceaa32a1d990f70fa" "move-to-document-start-end.js" >}}

### Navigate With Bookmarks

You can mark a place that you want to find and move to it again easily. You can insert as many bookmarks into your document as you want, and then navigate through them by identifying the bookmarks with unique names. You can move to a bookmark by using the [moveToBookmark](https://reference.aspose.com/words/nodejs-net/aspose.words/documentbuilder/moveToBookmark/) method.

The following code examples shows how to move a cursor position to a bookmark:

{{< gist "aspose-words-gists" "811254d9cf25578ceaa32a1d990f70fa" "move-to-bookmark.js" >}}

### Navigate to Table Cells

You can move to a table cell by using the [moveToCell](https://reference.aspose.com/words/nodejs-net/aspose.words/documentbuilder/moveToCell/) method. This method will enable you to navigate your cursor into any cell in a specific table. In addition, you can specify an index to move the cursor to any position or specified character in a cell within the [moveToCell](https://reference.aspose.com/words/nodejs-net/aspose.words/documentbuilder/moveToCell/) method.

The following code example shows how to move a cursor position to a specified table cell:

{{< gist "aspose-words-gists" "811254d9cf25578ceaa32a1d990f70fa" "move-to-table-cell.js" >}}

### Navigate to a Field

You can move to a specific field in your document by using the [moveToField](https://reference.aspose.com/words/nodejs-net/aspose.words/documentbuilder/moveToField/) method. In addition, you can move to a specific merge field by using the [moveToMergeField](https://reference.aspose.com/words/nodejs-net/aspose.words/documentbuilder/moveToMergeField/) method.

The following code example shows how to move the document builder cursor to a specific field:

{{< gist "aspose-words-gists" "811254d9cf25578ceaa32a1d990f70fa" "move-to-merge-field.js" >}}

### Navigate to a Header or Footer

You can move to the beginning of a header or footer by using the [moveToHeaderFooter](https://reference.aspose.com/words/nodejs-net/aspose.words/documentbuilder/moveToHeaderFooter/) method. 

The following code example shows how to move document builder cursor to a document header or footer:

{{< gist "aspose-words-gists" "811254d9cf25578ceaa32a1d990f70fa" "move-to-headers-footers.js" >}}

### Navigate to a Section or Paragraph

You can move to a specific section or paragraph by using the [moveToParagraph](https://reference.aspose.com/words/nodejs-net/aspose.words/documentbuilder/moveToParagraph/) or [moveToSection](https://reference.aspose.com/words/nodejs-net/aspose.words/documentbuilder/moveToSection/) methods. In addition, you can specify an index to move the cursor to any position or a specified character in a paragraph within the [moveToParagraph](https://reference.aspose.com/words/nodejs-net/aspose.words/documentbuilder/moveToParagraph/) method.

The following code example shows how to move to a specific section and a specific paragraph in a document:

{{< gist "aspose-words-gists" "811254d9cf25578ceaa32a1d990f70fa" "move-to-section.js" >}}
