p5.js | hide() Function
The hide() function is an inbuilt function which is used to hide the current element. Essentially display: none is used for this style.
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:
hide()
Parameters: This function does not accepts any parameters.
Below examples illustrate the hide() function in p5.js:
Example 1: This example uses hide() function to hide the div element.
function setup() { // Create Canvas of given size var cvs = createCanvas(600, 250); } function draw() { // Set the background color background('green'); // Use createDiv() function to // create a div element var myDiv1 = createDiv('GeeksforGeeks'); // Set the position of div element myDiv1.position(170, 30); // Set the div size myDiv1.size(200, 100); // Set the font-size of text myDiv1.style('font-size', '36px'); // Use createDiv() function to // create a div element var myDiv = createDiv('A computer science portal for geeks'); // Set the position of div element myDiv.position(180, 80); // Set the div size myDiv.size(200, 100); // Set the font-size of text myDiv.style('font-size', '24px'); // Set the font-size of text myDiv.style('border', '1px solid black'); // Set the font-size of text myDiv.style('text-align', 'center'); // Set the font color myDiv.style('color', 'white'); // Hide the div eleemnt myDiv.hide(); } |
Output:

Example 2: This example uses hide() and show() function to display the div element.
function setup() { // Create Canvas of given size var cvs = createCanvas(600, 250); } function draw() { // Set the background color background('green'); // Use createDiv() function to // create a div element var myDiv1 = createDiv('GeeksforGeeks'); // Set the position of div element myDiv1.position(170, 30); // Set the div size myDiv1.size(200, 100); // Set the font-size of text myDiv1.style('font-size', '36px'); // Use createDiv() function to // create a div element var myDiv = createDiv('A computer science portal for geeks'); // Set the position of div element myDiv.position(180, 80); // Set the div size myDiv.size(200, 100); // Set the font-size of text myDiv.style('font-size', '24px'); // Set the font-size of text myDiv.style('border', '1px solid black'); // Set the font-size of text myDiv.style('text-align', 'center'); // Set the font color myDiv.style('color', 'white'); // Hide the div element myDiv.hide(); // Show the div element myDiv.show(); } |
Output:

Recommended Posts:
- AngularJS | ng-hide Directive
- jQuery | hide() with Examples
- How to Show and Hide div elements using Checkboxes ?
- Hide the cursor in a webpage using CSS and JavaScript
- How to hide div element after few seconds in jQuery ?
- How to hide elements in responsive layout using CSS ?
- How to hide a div when the user clicks outside of it using jQuery?
- Show and hide password using JavaScript
- How to hide an element when printing a web page using CSS?
- How to hide Bootstrap modal with JavaScript?
- How to Show and Hide div elements using radio buttons?
- How to display icon next to show/hide text on button?
- Hide or show elements in HTML using display property
- Image Replacement in Bootstrap using text-hide Class
- Hide or show HTML elements using visibility property in JavaScript
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



