Interface Element

  • Elements are generic representations of content within a Google Docs document.

  • Various specific content types, such as ListItem, Paragraph, and Table, are considered elements and inherit methods from the genericElement.

  • The content includes a table listing numerous classes that implement the generic Element, along with brief descriptions of what each represents within a document.

  • A table of methods is provided, showing different ways to interact with an Element, including casting it to a specific type, copying, retrieving attributes, and navigating the document structure.

  • Detailed documentation for severalas methods demonstrates how to explicitly set an element's type for improved auto-completion and provides authorization scopes needed for these methods.

Element

A generic element.Document contents arerepresented as elements. For example,ListItem,Paragraph, andTable areelements and inherit all of the methods defined byElement, such asgetType().

Implementing classes

NameBrief description
BodyThe content of a tab in a Google Docs document.
ContainerElementA generic element that may contain other elements.
DateAn element representing a formatted date
EquationAn element representing a mathematical expression.
EquationFunctionAn element representing a function in a mathematicalEquation.
EquationFunctionArgumentSeparatorAn element representing a function separator in a mathematicalEquation.
EquationSymbolAn element representing a symbol in a mathematicalEquation.
FooterSectionAn element representing a footer section.
FootnoteAn element representing a footnote.
FootnoteSectionAn element representing a footnote section.
HeaderSectionAn element representing a header section.
HorizontalRuleAn element representing an horizontal rule.
InlineDrawingAn element representing an embedded drawing.
InlineImageAn element representing an embedded image.
ListItemAn element representing a list item.
PageBreakAn element representing a page break.
ParagraphAn element representing a paragraph.
PersonAn element representing a link to a person.
RichLinkAn element representing a link to a Google resource, such as a Drive file or a YouTube video.
TableAn element representing a table.
TableCellAn element representing a table cell.
TableOfContentsAn element containing a table of contents.
TableRowAn element representing a table row.
TextAn element representing a rich text region.
UnsupportedElementAn element representing a region that is unknown or cannot be affected by a script, such as apage number.

Methods

MethodReturn typeBrief description
asBody()BodyReturns the current element as aBody.
asDate()DateReturns the current element as aDate.
asEquation()EquationReturns the current element as anEquation.
asEquationFunction()EquationFunctionReturns the current element as aEquationFunction.
asEquationFunctionArgumentSeparator()EquationFunctionArgumentSeparatorReturns the current element as aEquationFunctionArgumentSeparator.
asEquationSymbol()EquationSymbolReturns the current element as aEquationSymbol.
asFooterSection()FooterSectionReturns the current element as aFooterSection.
asFootnote()FootnoteReturns the current element as aFootnote.
asFootnoteSection()FootnoteSectionReturns the current element as aFootnoteSection.
asHeaderSection()HeaderSectionReturns the current element as aHeaderSection.
asHorizontalRule()HorizontalRuleReturns the current element as aHorizontalRule.
asInlineDrawing()InlineDrawingReturns the current element as aInlineDrawing.
asInlineImage()InlineImageReturns the current element as aInlineImage.
asListItem()ListItemReturns the current element as aListItem.
asPageBreak()PageBreakReturns the current element as aPageBreak.
asParagraph()ParagraphReturns the current element as aParagraph.
asPerson()PersonReturns the current element as aPerson.
asRichLink()RichLinkReturns the current element as aRichLink, for example, a link to a Google Sheets file.
asTable()TableReturns the current element as aTable.
asTableCell()TableCellReturns the current element as aTableCell.
asTableOfContents()TableOfContentsReturns the current element as aTableOfContents.
asTableRow()TableRowReturns the current element as aTableRow.
asText()TextReturns the current element as aText.
copy()ElementReturns a detached, deep copy of the current element.
getAttributes()ObjectRetrieves the element's attributes.
getNextSibling()Element|nullRetrieves the element's next sibling element.
getParent()ContainerElement|nullRetrieves the element's parent element.
getPreviousSibling()Element|nullRetrieves the element's previous sibling element.
getType()ElementTypeRetrieves the element'sElementType.
isAtDocumentEnd()BooleanDetermines whether the element is at the end of theDocument.
merge()Element|nullMerges the element with the preceding sibling of the same type.
removeFromParent()Element|nullRemoves the element from its parent.
setAttributes(attributes)ElementSets the element's attributes.

Detailed documentation

asBody()

Returns the current element as aBody.

Use this method to aid auto-complete whenever a given element is known to be of a specifictype.

Return

Body — The current element.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asDate()

Returns the current element as aDate.

When you know an element is aDate, use this method to set its type as aDate. Doing so lets autocomplete in the Apps Script editor show you the methods you can usewith aDate.

Return

Date — The current element with its type set asDate.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asEquation()

Returns the current element as anEquation.

Use this method to aid auto-complete whenever a given element is known to be of a specifictype.

Return

Equation — The current element.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asEquationFunction()

Returns the current element as aEquationFunction.

Use this method to aid auto-complete whenever a given element is known to be of a specifictype.

Return

EquationFunction — The current element.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asEquationFunctionArgumentSeparator()

Returns the current element as aEquationFunctionArgumentSeparator.

Use this method to aid auto-complete whenever a given element is known to be of a specifictype.

Return

EquationFunctionArgumentSeparator — The current element.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asEquationSymbol()

Returns the current element as aEquationSymbol.

Use this method to aid auto-complete whenever a given element is known to be of a specifictype.

Return

EquationSymbol — The current element.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asFooterSection()

Returns the current element as aFooterSection.

Use this method to aid auto-complete whenever a given element is known to be of a specifictype.

Return

FooterSection — The current element.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asFootnote()

Returns the current element as aFootnote.

Use this method to aid auto-complete whenever a given element is known to be of a specifictype.

Return

Footnote — The current element.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asFootnoteSection()

Returns the current element as aFootnoteSection.

Use this method to aid auto-complete whenever a given element is known to be of a specifictype.

Return

FootnoteSection — The current element.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asHeaderSection()

Returns the current element as aHeaderSection.

Use this method to aid auto-complete whenever a given element is known to be of a specifictype.

Return

HeaderSection — The current element.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asHorizontalRule()

Returns the current element as aHorizontalRule.

Use this method to aid auto-complete whenever a given element is known to be of a specifictype.

Return

HorizontalRule — The current element.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asInlineDrawing()

Returns the current element as aInlineDrawing.

Use this method to aid auto-complete whenever a given element is known to be of a specifictype.

Return

InlineDrawing — The current element.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asInlineImage()

Returns the current element as aInlineImage.

Use this method to aid auto-complete whenever a given element is known to be of a specifictype.

Return

InlineImage — The current element.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asListItem()

Returns the current element as aListItem.

Use this method to aid auto-complete whenever a given element is known to be of a specifictype.

Return

ListItem — The current element.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asPageBreak()

Returns the current element as aPageBreak.

Use this method to aid auto-complete whenever a given element is known to be of a specifictype.

Return

PageBreak — The current element.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asParagraph()

Returns the current element as aParagraph.

Use this method to aid auto-complete whenever a given element is known to be of a specifictype.

Return

Paragraph — The current element.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asPerson()

Returns the current element as aPerson.

When you know an element is aPerson, use this method to set its type as a person.Doing so lets autocomplete in the Apps Script editor show you the methods you can use with aperson element.

Return

Person — The current element with its type set asPerson.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asRichLink()

Returns the current element as aRichLink, for example, a link to a Google Sheets file.

When you know an element is aRichLink, use this method to set its type as aRichLink. Doing so lets autocomplete in the Apps Script editor show you the methods you canuse with aRichLink.

Return

RichLink — The current element with its type set asRichLink.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asTable()

Returns the current element as aTable.

Use this method to aid auto-complete whenever a given element is known to be of a specifictype.

Return

Table — The current element.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asTableCell()

Returns the current element as aTableCell.

Use this method to aid auto-complete whenever a given element is known to be of a specifictype.

Return

TableCell — The current element.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asTableOfContents()

Returns the current element as aTableOfContents.

Use this method to aid auto-complete whenever a given element is known to be of a specifictype.

Return

TableOfContents — The current element.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asTableRow()

Returns the current element as aTableRow.

Use this method to aid auto-complete whenever a given element is known to be of a specifictype.

Return

TableRow — The current element.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asText()

Returns the current element as aText.

Use this method to aid auto-complete whenever a given element is known to be of a specifictype.

Return

Text — The current element.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

copy()

Returns a detached, deep copy of the current element.

Any child elements present in the element are also copied. The new element doesn't have aparent.

Return

Element — The new copy.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getAttributes()

Retrieves the element's attributes.

The result is an object containing a property for each valid element attribute where eachproperty name corresponds to an item in theDocumentApp.Attribute enumeration.

constdoc=DocumentApp.getActiveDocument();constdocumentTab=doc.getActiveTab().asDocumentTab();constbody=documentTab.getBody();// Append a styled paragraph.constpar=body.appendParagraph('A bold, italicized paragraph.');par.setBold(true);par.setItalic(true);// Retrieve the paragraph's attributes.constatts=par.getAttributes();// Log the paragraph attributes.for(constattinatts){Logger.log(`${att}:${atts[att]}`);}

Return

Object — The element's attributes.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getNextSibling()

Retrieves the element's next sibling element.

The next sibling has the same parent and follows the current element.

Return

Element|null — The next sibling element.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getParent()

Retrieves the element's parent element.

The parent element contains the current element.

Return

ContainerElement|null — The parent element.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getPreviousSibling()

Retrieves the element's previous sibling element.

The previous sibling has the same parent and precedes the current element.

Return

Element|null — The previous sibling element.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getType()

Retrieves the element'sElementType.

UsegetType() to determine the exact type of a given element.

constdoc=DocumentApp.getActiveDocument();constdocumentTab=doc.getActiveTab().asDocumentTab();constbody=documentTab.getBody();// Obtain the first element in the active tab's body.constfirstChild=body.getChild(0);// Use getType() to determine the element's type.if(firstChild.getType()===DocumentApp.ElementType.PARAGRAPH){Logger.log('The first element is a paragraph.');}else{Logger.log('The first element is not a paragraph.');}

Return

ElementType — The element type.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

isAtDocumentEnd()

Determines whether the element is at the end of theDocument.

Return

Boolean — Whether the element is at the end of the tab.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

merge()

Merges the element with the preceding sibling of the same type.

Only elements of the sameElementType can be merged. Any child elements contained inthe current element are moved to the preceding sibling element.

The current element is removed from the document.

constdoc=DocumentApp.getActiveDocument();constdocumentTab=doc.getActiveTab().asDocumentTab();constbody=documentTab.getBody();// Example 1: Merge paragraphs// Append two paragraphs to the document's active tab.constpar1=body.appendParagraph('Paragraph 1.');constpar2=body.appendParagraph('Paragraph 2.');// Merge the newly added paragraphs into a single paragraph.par2.merge();// Example 2: Merge table cells// Create a two-dimensional array containing the table's cell contents.constcells=[['Row 1, Cell 1','Row 1, Cell 2'],['Row 2, Cell 1','Row 2, Cell 2'],];// Build a table from the array.consttable=body.appendTable(cells);// Get the first row in the table.constrow=table.getRow(0);// Get the two cells in this row.constcell1=row.getCell(0);constcell2=row.getCell(1);// Merge the current cell into its preceding sibling element.constmerged=cell2.merge();

Return

Element|null — The merged element.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

removeFromParent()

Removes the element from its parent.

constdoc=DocumentApp.getActiveDocument();constdocumentTab=doc.getActiveTab().asDocumentTab();constbody=documentTab.getBody();// Remove all images in the active tab's body.constimgs=body.getImages();for(leti=0;i <imgs.length;i++){imgs[i].removeFromParent();}

Return

Element|null — The removed element.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

setAttributes(attributes)

Sets the element's attributes.

The specified attributes parameter must be an object where each property name is an item intheDocumentApp.Attribute enumeration and each property value is the new value to beapplied.

constdoc=DocumentApp.getActiveDocument();constdocumentTab=doc.getActiveTab().asDocumentTab();constbody=documentTab.getBody();// Define a custom paragraph style.conststyle={};style[DocumentApp.Attribute.HORIZONTAL_ALIGNMENT]=DocumentApp.HorizontalAlignment.RIGHT;style[DocumentApp.Attribute.FONT_FAMILY]='Calibri';style[DocumentApp.Attribute.FONT_SIZE]=18;style[DocumentApp.Attribute.BOLD]=true;// Append a plain paragraph.constpar=body.appendParagraph('A paragraph with custom style.');// Apply the custom style.par.setAttributes(style);

Parameters

NameTypeDescription
attributesObjectThe element's attributes.

Return

Element — The current element.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-11 UTC.