p5.js parent() Function
Last Updated :
03 Mar, 2021
The parent() function is used to attach the element as a parent element. This function accepts either a string ID, DOM node, or p5.Element. This function returns the parent node if it does not contain any parameters.
Syntax:
parent( parent )
or
parent()
Parameters: It contains single parameter parent which holds the string p5.Element Object as element.
Below example illustrates the parent() function in p5.js:
Example:
function setup() {
var cvs = createCanvas(600, 250);
}
function draw() {
background( 'green' );
var myDiv = createDiv( 'GeeksforGeeks' );
var myDiv1 = createDiv( 'A computer science portal for geeks' );
myDiv1.parent(myDiv);
myDiv.position(150, 100);
myDiv.style( 'text-align' , 'center' );
myDiv.style( 'font-size' , '24px' );
myDiv.style( 'color' , 'white' );
}
|
Output:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...