Patrickkx
Patrickkx

Reputation: 1870

How to add an id to canvas generated by Konva?

Is there a way to somehow add unique id to the canvas generated by konva? Its nested inside the 'container' div and one more div. It's pretty difficult to get to it, would be much easier if there would be a way to add id to it.

Upvotes: 2

Views: 1184

Answers (2)

lavrton
lavrton

Reputation: 20363

There is no public API for that yet, but with the last version of [email protected] you can do this:

const canvas = layer.getCanvas()._canvas;
canvas.id = 'new-id';

Upvotes: 4

Manuel Gozzi
Manuel Gozzi

Reputation: 21

If you're trying to get a canvas you could select it via

const konvaCanvas = document.querySelector('canvas');

and then try to add an id by doing this

konvaCanvas.setAttribute("id", "whatever-id-you-want");

Let me know if this works
Have a good one!

Upvotes: 1

Related Questions