BookmarkCollection class

BookmarkCollection class

A collection of Bookmark objects that represent the bookmarks in the specified range. To learn more, visit the Working with Bookmarks documentation article.

Properties

NameDescription
countReturns the number of bookmarks in the collection.
this[]
this[]

Methods

NameDescription
clear()Removes all bookmarks from this collection and from the document.
remove(bookmark)Removes the specified bookmark from the document.
remove(bookmarkName)Removes a bookmark with the specified name.
removeAt(index)Removes a bookmark at the specified index.

Examples

Shows how to add bookmarks and update their contents.

test('CreateUpdateAndPrintBookmarks', () => {
  // Create a document with three bookmarks, then use a custom document visitor implementation to print their contents.
  let doc = CreateDocumentWithBookmarks(3);
  let bookmarks = doc.range.bookmarks;
  expect(bookmarks.count).toEqual(3);

  // Bookmarks can be accessed in the bookmark collection by index or name, and their names can be updated.
  bookmarks.at(0).name = `${bookmarks.at(0).name}_NewName`;
  bookmarks.at("MyBookmark_2").text = `Updated text contents of ${bookmarks.at(1).name}`;
});

See Also