p5.js | hide() Function
Last Updated :
08 Jun, 2021
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.
javascript
<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.
javascript
function setup() {
var cvs = createCanvas(600, 250);
}
function draw() {
background( 'green' );
var myDiv1 = createDiv( 'GeeksforGeeks' );
myDiv1.position(170, 30);
myDiv1.size(200, 100);
myDiv1.style( 'font-size' , '36px' );
var myDiv = createDiv( 'A computer science portal for geeks' );
myDiv.position(180, 80);
myDiv.size(200, 100);
myDiv.style( 'font-size' , '24px' );
myDiv.style( 'border' , '1px solid black' );
myDiv.style( 'text-align' , 'center' );
myDiv.style( 'color' , 'white' );
myDiv.hide();
}
|
Output:
Example 2: This example uses hide() and show() function to display the div element.
javascript
function setup() {
var cvs = createCanvas(600, 250);
}
function draw() {
background( 'green' );
var myDiv1 = createDiv( 'GeeksforGeeks' );
myDiv1.position(170, 30);
myDiv1.size(200, 100);
myDiv1.style( 'font-size' , '36px' );
var myDiv = createDiv( 'A computer science portal for geeks' );
myDiv.position(180, 80);
myDiv.size(200, 100);
myDiv.style( 'font-size' , '24px' );
myDiv.style( 'border' , '1px solid black' );
myDiv.style( 'text-align' , 'center' );
myDiv.style( 'color' , 'white' );
myDiv.hide();
myDiv.show();
}
|
Output:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...