p5.js | child() Function
The child() function is used to add the element as a child element to the parent element. This function accepts either a string ID, DOM node, or p5.Element. If this function does not contain any parameters then it returns an array of children DOM nodes.
Note: This function uses the 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:
child()
or
child( child )
Parameters: This function accepts single parameter child which holds the string or p5.Element. The ID, DOM node, or p5.Element is used to add as a current element.
Return Value: It returns an array of child nodes.
Below example illustrates the child() 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('GeeksforGeeks'); var myDiv1 = createDiv('A computer science portal for geeks'); // Use child() function myDiv.child(myDiv1); // 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:

Recommended Posts:
- CSS | :only-child Selector
- CSS | :last-child Selector
- How to use a not:first-child selector in CSS?
- CSS | :first-child Selector
- CSS | :nth-last-child() Selector
- CSS | :nth-child() Selector
- jQuery | :only-child Selector
- CSS Child vs Descendant selectors
- jQuery | :nth-last-child() Selector
- jQuery | :nth-child() Selector
- jQuery | :last-child Selector
- jQuery | :first-child Selector
- How to get specific number of child elements using CSS?
- jQuery | parent > child Selector
- How to get the child element of a parent using 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.



