JSFiddle - React, Tailwind, and code Playground

HTML

<div id="container">

</div>

<button onclick="foo()">Append image</button>

JavaScript

function foo()
{
			var circle = getStateCircle("opened");
      
      
      var dataUrl = circle.toDataURL("image/png");
      
      var img = document.createElement("img");
      
      img.src = dataUrl;
      document.getElementById("container").appendChild(circle);
}



function getStateCircle(state)
{
                var stateCircle;

                if(state === "opened")
                {
                    stateCircle = new Circle("#ffcc00", "20");
                }

                else if(state === "accepted")
                {
                    stateCircle = new Circle("#33cc33", "20");
                }

                else if (state === "refused")
                {
                    stateCircle = new Circle("#ff3300", "20");
                }

                else if (state === "closed")
                {
                    stateCircle = new Circle("black", "20");
                }

                else
                {
                    throw new Error("The state of the offer is unknown");
                }
                    
                stateCircle.buildCircle();
                var circle = stateCircle.getCircle();
                

                return circle;
}

function Circle(color, size)
{
    this._color = color;
    this._size = size;

    this._circle;

    this.buildCircle = function()
    {


        this._circle = new ElementBuilder("canvas").withAttribute("height", this._size).getElement();
        var context = this._circle.getContext("2d")
       	context.strokeStyle = this._color;
        context.beginPath();
        context.arc(this._size/2,this._size/2,this._size/2,0,2*Math.PI);
        context.stroke();
        context.fillStyle = this._color;
        context.fill();
        
    }

    this.buildCircleAndAppendTo = function(father)
    {
        this._buildCircle();
        father.appendChild(this._circle);
    }

    this.getCircle = function()
    {
        return this._circle;
    }
}

function...