2

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.

craigcaulfield
  • 3,381
  • 10
  • 32
  • 40
Patrickkx
  • 1,740
  • 7
  • 31
  • 60

2 Answers2

4

There is no public API for that yet, but with the last version of konva@4.0.10 you can do this:

const canvas = layer.getCanvas()._canvas;
canvas.id = 'new-id';
lavrton
  • 18,973
  • 4
  • 30
  • 63
1

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!