p5.js | createElement() Function

The createElement() function is used to create a element in the DOM (Document Object Model). The .position() function is used to set the position of the element.

Note: This function requires the p5.dom library. So add the following line in the head section of the index.html file.

filter_none

edit
close

play_arrow

link
brightness_4
code

chevron_right


Syntax:



createElement( tag, [content] )

Parameters: This function accepts two parameters as mentioned above and described below:

  • tag: This parameter holds the tag for the new element.
  • content: This parameter holds the html content to be inserted into the element

Return Value: It returns a pointer element holding the created node object.

Example: This example uses createElement() function to create the element.

filter_none

edit
close

play_arrow

link
brightness_4
code

function setup() {
  // create canavas
  createCanvas(400, 400);
}
  
function draw() {
  // set background color
  background(150, 255, 134);
  // create the eelment 
  create_element = createElement('h1', ["GeeksForGeeks!"]); 
    
  // position the element
  create_element.position(50, 100); 
        
}

chevron_right


Output:

Reference: https://p5js.org/reference/#/p5/createElement




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.