ctx.element
An ElementProxy instance pointing to the sandbox DOM container, serving as the default rendering target for ctx.render(). It is available in scenarios where a rendering container exists, such as JSBlock, JSField, JSItem, and JSColumn.
Applicable Scenarios
Note:
ctx.elementis only available in RunJS contexts that have a rendering container. In contexts without a UI (such as pure backend logic), it may beundefined. It is recommended to perform a null check before use.
Type Definition
Security Requirements
Recommended: All rendering should be performed via ctx.render(). Avoid using the DOM APIs of ctx.element directly (e.g., innerHTML, appendChild, querySelector, etc.).
Why ctx.render() is Recommended
❌ Not Recommended: Direct Manipulation of ctx.element
ctx.element.innerHTMLis deprecated. Please usectx.render()instead.
✅ Recommended: Using ctx.render()
Special Case: As a Popover Anchor
When you need to open a Popover using the current element as an anchor, you can access ctx.element?.__el to get the raw DOM as the target:
Use
__elonly in scenarios like "using the current container as an anchor"; do not manipulate the DOM directly in other cases.
Relationship with ctx.render
- If
ctx.render(vnode)is called without acontainerargument, it renders into thectx.elementcontainer by default. - If both
ctx.elementis missing and nocontaineris provided, an error will be thrown. - You can explicitly specify a container:
ctx.render(vnode, customContainer).
Notes
ctx.elementis intended for internal use byctx.render(). Directly accessing or modifying its properties/methods is not recommended.- In contexts without a rendering container,
ctx.elementwill beundefined. Ensure the container is available or pass acontainermanually before callingctx.render(). - Although
innerHTML/outerHTMLinElementProxyare sanitized via DOMPurify, it is still recommended to usectx.render()for unified rendering management.
Related
- ctx.render: Rendering content into a container
- ctx.view: Current view controller
- ctx.modal: Shortcut API for modals

