Function createOrResolve

Creates and appends a SVG element.

// Create a circle
const circleEl = createOrResolve(parentEl, `SVGCircleElement`);

If queryOrExisting is specified, it is used as a query to find an existing element. If query starts with #, this will be set as the element id, if created.

// Creates an element with id 'myCircle' if it doesn't exist
const circleEl = createOrResolve(parentEl, `SVGCircleElement`, `#myCircle`);
  • Type Parameters

    • V extends SVGElement

    Parameters

    • parent: SVGElement

      Parent element

    • type: string

      Type of SVG element

    • OptionalqueryOrExisting: string | V

      Query, eg #id

    • Optionalsuffix: string

    Returns V