appendChild() problem

hi! I’m trying to create an animation but I keep getting this error “cannot read appendChild property”
this is my code:

function divCreater() {

    for (let i = 0; i < 100; i++) {

        let div = document.createElement("div");

        div.classList.add("div")



        let a=Math.random()*window.innerWidth;

        let b=Math.random()*window.innerHeight;

        

       div.x=a;

       div.y=b;



      document.body.appendChild(div)

    }

};

are you sure that this is how you select the canvas? I don’t think the document has a canvas property

On the appendChild you’re using a string, not the variable.
Change it to document.canvas.appendChild(div)

1 Like