Get element children

element.getChildren()

Get child elements from a parent element in the element hierarchy.

You can also check the read-only children property to see if an element can have children. Having this property enables methods related to children, such as element.append(), element.prepend(), element.after(), and element.before().

Syntax

element.getChildren(): Promise<Array<AnyElement>>

Returns

Promise<Array<AnyElement>>

A Promise that resolves to an array of AnyElement objects.

AnyElement represents the various element types available in a Webflow project. See a full list of supported element types in our Designer Extension type definitions.

Example

// Get Selected Element
const selectedElement = await webflow.getSelectedElement();
if (selectedElement?.children) {
// Get Children
const children = await selectedElement.getChildren();
// Get Children Details
const childrenDetailsPromises = children.map(async (child) => {
// Get style details of children (This is the name of the element in the Designer)
let styleDetails = null;
let childStyles = child.styles ? await child.getStyles() : null;
if (childStyles) {
const styleNamesPromises = childStyles.map(style => style.getName());
styleDetails = await Promise.all(styleNamesPromises);
}
return {
styleDetails,
};
});
// Print details of child elements
const childrenDetails = await Promise.all(childrenDetailsPromises);
console.log(childrenDetails); // This will now log the array of child details
}

Designer Ability

Checks for authorization only

Designer AbilityLocaleBranchWorkflowSitemode
canAccessCanvasAnyAnyAnyAny