How to put p5.js canvas in a html div

Meghan Rose picture Meghan Rose · Feb 26, 2016 · Viewed 15.9k times · Source

I am trying to add p5.js to the background of one section in my webpage. I am new to javascript and can't figure out how to bind the two parts together.

Answer

Michael Paccione picture Michael Paccione · Apr 11, 2016

You need to add code in your setup.

Make sure you have the function in a script tag in the html as well. Note you do not add # in the .parent().

var myCanvas = createCanvas(winWidth, winHeight);
    myCanvas.parent("idnameofdiv");