Sunday, November 17, 2024
Google search engine
HomeLanguagesJavascriptp5.js parent() Function

p5.js parent() Function

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() {  
     
    // 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 myDiv = createDiv('neveropen');
    
    var myDiv1 = createDiv('A computer science portal for neveropen');
    
    // Use parent() function
    myDiv1.parent(myDiv);
    
    // Set the position of div element
    myDiv.position(150, 100);  
    
    myDiv.style('text-align', 'center');
    
    // Set the font-size of text
    myDiv.style('font-size', '24px');
    
    // Set the font color
    myDiv.style('color', 'white');
  
}


Output:

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen 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!

RELATED ARTICLES

Most Popular

Recent Comments