Bulk Add Elements
webflow.elementBuilder(preset)
Creates a builder for efficiently constructing complex element hierarchies before adding them to the canvas. This method is optimized for bulk creation of elements, particularly useful when dealing with complex hierarchical designs like SVG graphics or nested components.
The element builder approach allows you to:
- Create an entire structure of elements in memory
- Configure all elements before adding to the canvas
- Add the entire structure to the canvas in a single operation
Current Limitations
- DOM Elements Only: Currently, only DOM elements can be used as root or child elements with this method.
- Canvas Insertion: The builder elements must be appended to an actual element on the canvas to be visible.
- Setting styles and text content: Styles and text content must be set after the elements are added to the canvas.
Syntax
Parameters
- preset: The DOM element preset from the Webflow presets. Currently, only DOM elements are supported.
Returns
BuilderElement
A builder element object designed for creating and manipulating hierarchical structures. This object has methods like:
append()
: Add a child element to this builder elementsetTag()
: Set the HTML tag for this DOM elementsetAttribute()
: Set an attribute on this DOM element
Examples
SVG with multiple paths
Create a navigation menu
This example shows how to create a nested SVG structure:
When to use element builder
The element builder is particularly useful for:
- Complex Element Structures: When creating hierarchies with many nested elements
- SVG Creation: Perfect for building SVG graphics with many path, circle, or other elements
- Repeating Patterns: When you need to create many similar elements
- Performance: More efficient than adding elements one-by-one to the canvas
Best practices
- Build Complete Structures: Create your entire element structure before adding it to the canvas
- Set Properties: Configure tags and attributes on builder elements before appending
- Set Styles and Text Content after building: Set styles and text content after elements are added to the canvas
- Track References: If you need to modify elements after adding to canvas, store references to them
- Batch Operations: Use
Promise.all
for batch operations when modifying multiple elements