The remove() function is an inbuilt function which is used to remove the element and deregister all listeners.
This function requires p5.dom library. So add the following line in the head section of the index.html file.
<script language= "javascript"
type= "text/javascript" src= "path/to/p5.dom.js" >
</script>
|
Syntax:
remove()
Parameters: This function does not accepts any parameters.
Below examples illustrate the remove() function in p5.js:
Example 1: This example creates an element.
function setup() {
var cvs = createCanvas(600, 250);
}
function draw() {
background( 'green' );
var myDiv = createDiv( 'Welcome to GeeksforGeeks' );
myDiv.position(150, 100);
myDiv.style( 'font-size' , '24px' );
myDiv.style( 'color' , 'white' );
}
|
Output:

Example 2: This example uses remove() function to remove the element.
function setup() {
var cvs = createCanvas(600, 250);
}
function draw() {
background( 'green' );
var myDiv = createDiv( 'Welcome to GeeksforGeeks' );
myDiv.position(150, 100);
myDiv.style( 'font-size' , '24px' );
myDiv.style( 'color' , 'white' );
myDiv.remove();
}
|
Output:

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
16 Aug, 2023
Like Article
Save Article