svgdotjs / svgdom

Straightforward DOM implementation to make SVG.js run headless on Node.js
MIT License
269 stars 53 forks source link

How to use referencing in svgdom? #85

Closed mtrnik closed 2 years ago

mtrnik commented 2 years ago

In svg.js there are these functions which allow developer to reference elements from existing svg. Is it possible to use these functions in svgdom? And how?

https://svgjs.dev/docs/3.0/referencing-creating-elements/#element-findone

I've tried multiple ways but with no success.

Example:

const { createSVGWindow } = require('svgdom')
const window = createSVGWindow()
const SVG = require('svg.js')(window)
const document = window.document

const canvas = SVG(document.documentElement)
canvas.svg('<circle class="circle1" cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" />')
let circle = canvas.findOne('.circle1')
circle.fill('black')

result: TypeError: canvas.findOne is not a function at .../functions/src/generateSvg.js

Fuzzyma commented 2 years ago

You either use the wrong version or the wrong code. Please look into the readme and the docs to see what version supports which functions. `findOne is a function of svg.js v3 but you imported v2

mtrnik commented 2 years ago

Thank you, that helped.