Interface Element Stay organized with collections Save and categorize content based on your preferences.
Page Summary
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 generic
Element.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 several
asmethods demonstrates how to explicitly set an element's type for improved auto-completion and provides authorization scopes needed for these methods.
A generic element.Document contents arerepresented as elements. For example,List,Paragraph, andTable areelements and inherit all of the methods defined byElement, such asget.
Implementing classes
| Name | Brief description |
|---|---|
Body | The content of a tab in a Google Docs document. |
Container | A generic element that may contain other elements. |
Date | An element representing a formatted date |
Equation | An element representing a mathematical expression. |
Equation | An element representing a function in a mathematicalEquation. |
Equation | An element representing a function separator in a mathematicalEquation. |
Equation | An element representing a symbol in a mathematicalEquation. |
Footer | An element representing a footer section. |
Footnote | An element representing a footnote. |
Footnote | An element representing a footnote section. |
Header | An element representing a header section. |
Horizontal | An element representing an horizontal rule. |
Inline | An element representing an embedded drawing. |
Inline | An element representing an embedded image. |
List | An element representing a list item. |
Page | An element representing a page break. |
Paragraph | An element representing a paragraph. |
Person | An element representing a link to a person. |
Rich | An element representing a link to a Google resource, such as a Drive file or a YouTube video. |
Table | An element representing a table. |
Table | An element representing a table cell. |
Table | An element containing a table of contents. |
Table | An element representing a table row. |
Text | An element representing a rich text region. |
Unsupported | An element representing a region that is unknown or cannot be affected by a script, such as apage number. |
Methods
| Method | Return type | Brief description |
|---|---|---|
as | Body | Returns the current element as aBody. |
as | Date | Returns the current element as aDate. |
as | Equation | Returns the current element as anEquation. |
as | Equation | Returns the current element as aEquation. |
as | Equation | Returns the current element as aEquation. |
as | Equation | Returns the current element as aEquation. |
as | Footer | Returns the current element as aFooter. |
as | Footnote | Returns the current element as aFootnote. |
as | Footnote | Returns the current element as aFootnote. |
as | Header | Returns the current element as aHeader. |
as | Horizontal | Returns the current element as aHorizontal. |
as | Inline | Returns the current element as aInline. |
as | Inline | Returns the current element as aInline. |
as | List | Returns the current element as aList. |
as | Page | Returns the current element as aPage. |
as | Paragraph | Returns the current element as aParagraph. |
as | Person | Returns the current element as aPerson. |
as | Rich | Returns the current element as aRich, for example, a link to a Google Sheets file. |
as | Table | Returns the current element as aTable. |
as | Table | Returns the current element as aTable. |
as | Table | Returns the current element as aTable. |
as | Table | Returns the current element as aTable. |
as | Text | Returns the current element as aText. |
copy() | Element | Returns a detached, deep copy of the current element. |
get | Object | Retrieves the element's attributes. |
get | Element|null | Retrieves the element's next sibling element. |
get | Container | Retrieves the element's parent element. |
get | Element|null | Retrieves the element's previous sibling element. |
get | Element | Retrieves the element'sElement. |
is | Boolean | Determines whether the element is at the end of theDocument. |
merge() | Element|null | Merges the element with the preceding sibling of the same type. |
remove | Element|null | Removes the element from its parent. |
set | Element | Sets 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.currentonlyhttps://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.currentonlyhttps://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.currentonlyhttps://www.googleapis.com/auth/documents
asEquationFunction()
Returns the current element as aEquation.
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.currentonlyhttps://www.googleapis.com/auth/documents
asEquationFunctionArgumentSeparator()
Returns the current element as aEquation.
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.currentonlyhttps://www.googleapis.com/auth/documents
asEquationSymbol()
Returns the current element as aEquation.
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.currentonlyhttps://www.googleapis.com/auth/documents
asFooterSection()
Returns the current element as aFooter.
Use this method to aid auto-complete whenever a given element is known to be of a specifictype.
Return
Footer — The current element.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/documents.currentonlyhttps://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.currentonlyhttps://www.googleapis.com/auth/documents
asFootnoteSection()
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.currentonlyhttps://www.googleapis.com/auth/documents
asHeaderSection()
Returns the current element as aHeader.
Use this method to aid auto-complete whenever a given element is known to be of a specifictype.
Return
Header — The current element.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/documents.currentonlyhttps://www.googleapis.com/auth/documents
asHorizontalRule()
Returns the current element as aHorizontal.
Use this method to aid auto-complete whenever a given element is known to be of a specifictype.
Return
Horizontal — The current element.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/documents.currentonlyhttps://www.googleapis.com/auth/documents
asInlineDrawing()
Returns the current element as aInline.
Use this method to aid auto-complete whenever a given element is known to be of a specifictype.
Return
Inline — The current element.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/documents.currentonlyhttps://www.googleapis.com/auth/documents
asInlineImage()
Returns the current element as aInline.
Use this method to aid auto-complete whenever a given element is known to be of a specifictype.
Return
Inline — The current element.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/documents.currentonlyhttps://www.googleapis.com/auth/documents
asListItem()
Returns the current element as aList.
Use this method to aid auto-complete whenever a given element is known to be of a specifictype.
Return
List — The current element.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/documents.currentonlyhttps://www.googleapis.com/auth/documents
asPageBreak()
Returns the current element as aPage.
Use this method to aid auto-complete whenever a given element is known to be of a specifictype.
Return
Page — The current element.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/documents.currentonlyhttps://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.currentonlyhttps://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.currentonlyhttps://www.googleapis.com/auth/documents
asRichLink()
Returns the current element as aRich, for example, a link to a Google Sheets file.
When you know an element is aRich, use this method to set its type as aRich. Doing so lets autocomplete in the Apps Script editor show you the methods you canuse with aRich.
Return
Rich — The current element with its type set asRich.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/documents.currentonlyhttps://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.currentonlyhttps://www.googleapis.com/auth/documents
asTableCell()
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.currentonlyhttps://www.googleapis.com/auth/documents
asTableOfContents()
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.currentonlyhttps://www.googleapis.com/auth/documents
asTableRow()
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.currentonlyhttps://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.currentonlyhttps://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.currentonlyhttps://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 theDocument 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.currentonlyhttps://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.currentonlyhttps://www.googleapis.com/auth/documents
getParent()
Retrieves the element's parent element.
The parent element contains the current element.
Return
Container — The parent element.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/documents.currentonlyhttps://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.currentonlyhttps://www.googleapis.com/auth/documents
getType()
Retrieves the element'sElement.
Useget 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
Element — The element type.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/documents.currentonlyhttps://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.currentonlyhttps://www.googleapis.com/auth/documents
merge()
Merges the element with the preceding sibling of the same type.
Only elements of the sameElement 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.currentonlyhttps://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.currentonlyhttps://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 intheDocument 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
| Name | Type | Description |
|---|---|---|
attributes | Object | The 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.currentonlyhttps://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.