I have a canvas. Now i want to make an image of the canvas. This function i already developed. I've got an image with the right src-attribute. But if i want to append this image-element to the html-container, it doesn't works. Nothing happens.
I don't know why. The html-container is available, the image is correct.
Here is some code:
Function to create the picture
function createPicture(canvas, container){
let dataURL = canvas.toDataURL({
width: canvas.width,
height: canvas.height,
left: 0,
top: 0,
format: 'jpeg',
});
let image = new Image();
image.setAttribute("src", dataURL);
container.append(image);
}
Calling this function
createPicture(canvas, $("#test"));
Image in the console:
<img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAADâĤ">
Your code works fine for me, see my sample below
Only thing I could think of is you are doing something on your canvas after you call the createPicture an expecting it to be there, if you still run into problems I would recommend you to create a code snippet reproducing your problem and post it here
Check on your dev console, make sure you see the image element:

If you don't see it then the problem must be the container