svgdotjs / svg.js

The lightweight library for manipulating and animating SVG
https://svgjs.dev
Other
11.15k stars 1.08k forks source link

SVG.select is not a function - how to select with v >3? #1029

Closed wmadam closed 5 years ago

wmadam commented 5 years ago

Bug report

Using SVG.js v 3.0.2 now (2.7 before)

I have an SVG inline in my code like

....

Based on this I am creating a SVG.Element by using

const svgRootImage = document.getElementById("floorplan");
const svgRootObj = SVG.adopt(svgRootImage);

When afterwards creating a circle in that SVG via

svgRootObj.circle(100);

It works fine.

But when I try to select an element within the SVG (there is a in the svg) via:

const sBox1Obj = svgRootObj.select("g.sBoxClass");

SVG.js tell me `svgRootObj.select is not a function``

What am I doing wrong? When using SVG.js 2.x it worked fine.

Fuzzyma commented 5 years ago

Select does not work (yet) for version 3. Anyway, why are you using 3.0.2 when there is 3.0.12 available? Additionally you kinda use it wrong but thats not your fault because the docs are not up to date. Visit the issue tracker for more info or join the chat at gitter or see examples at twitter

sanscore commented 5 years ago

Could you elaborate more? Either link to the "issue tracker" or suggest a workaround. Is there another "issue tracker" besides the Github Issues? If there's related issue or PR or Project, I cannot find it.

Edit: Issues #948 and #954 have useful documentation for transitioning from 2.x to 3.x. To replace .select(...), try .find(...).

Fuzzyma commented 5 years ago

Today I finally updated the docs were the new ways to reference svg elements is shown. Basically you have the following possibilities:

var el = SVG(selector) // get an elemenet by css selector
var list = SVG.find(selector) // get all elements matched by the selector

var el = group.findOne(selector) // like SVG but inside the group
var list = group.find(selector) // like SVG.find but inside the group