Skip to content
Related Articles

Related Articles

p5.js parent() Function

View Discussion
Improve Article
Save Article
  • Last Updated : 03 Mar, 2021
View Discussion
Improve Article
Save Article

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.


parent( 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:


function setup() {  
    // Create Canvas of given size 
    var cvs = createCanvas(600, 250);
function draw() {
    // Set the background color
    // Use createDiv() function to
    // create a div element
    var myDiv = createDiv('GeeksforGeeks');
    var myDiv1 = createDiv('A computer science portal for geeks');
    // Use parent() function
    // Set the position of div element
    myDiv.position(150, 100);  'text-align', 'center');
    // Set the font-size of text'font-size', '24px');
    // Set the font color'color', 'white');


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!