I\'m trying to add a canvas over another canvas – how can I make this function wait to start until the first canvas is created?
function PaintObject(brush) {
A more modern approach to waiting for elements:
while(!document.querySelector(".my-selector")) { await new Promise(r => setTimeout(r, 500)); } // now the element is loaded
Note that this code would need to be wrapped in an async function.