Skip to content
Related Articles
Open in App
Not now

Related Articles

p5.js | removeElements() Function

Improve Article
Save Article
  • Last Updated : 17 Jan, 2020
Improve Article
Save Article

The removeElements() function is used to remove all the elements currently present that are created by p5, except those that are created using the createCanvas() function or createGraphics() function. The elements are removed from the DOM along with their event handlers.



Parameters: This function doesn’t accept any parameter.

Below example illustrates the removeElements() function in p5.js:


function setup() {
  createCanvas(600, 300);
  text("Click the mouse button to create elements", 10, 20);
  text("Click on the button below to remove all elements", 10, 50);
  // button to remove elements
  removeBtn = createButton('Remove All');
  removeBtn.position(20, 80);
function mouseClicked() {
  // create element at mouse position
  createDiv('element').position(mouseX, mouseY);
function removeAll() {
  // remove all elements


Online editor:
Environment Setup:


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!