p5.js | select() Function
The select() function is used to search an element in the page with the given id, class or tag name and return it as a p5.element. It has a syntax similar to the CSS selector. An optional parameter is available that can be used to search within a given element. This method only returns the first element if multiple elements exist on the page that matches the selector.
Note: The DOM node of the element can be accessed using the .elt property.
Parameters: This function accept two parameters as mentioned above and described below:
- name: It is a string which denotes the id, class or tag name of the element that has to be searched.
- container: It is an optional parameter which denotes an element to search.
Return Value: When the given element is successfully found, it returns a p5.element that contains the node. Otherwise, it returns null.
Below examples illustrates the select() function in p5.js:
Online editor: https://editor.p5js.org/