Skip to content

Node.createSvg method

Node › createSvg

Official

Creates a new svg element such as <svg>, <circle>, <rect>, etc.

Signature:

createSvg(tag: K, o?: string | SvgElementInfo, callback?: (el: SVGElementTagNameMap[K]) => void): SVGElementTagNameMap[K]

Parameters:

ParameterTypeDescription
tagKThe tag name of the element to create.
o?string | SvgElementInfoThe options object.
callback?(el: SVGElementTagNameMap[K]) => voidA callback function to be called when the element is created.

Returns: SVGElementTagNameMap[K] — The created element.

Example:

document.body.createSvg('svg', { cls: 'foo bar' }, (svg) => {
svg.createSvg('circle');
});