p5.js | attribute() Function Last Updated : 27 Aug, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report The attribute() function is used to add a new attribute or change the value of an existing attribute on the specified element. If the attribute does not specify any value it returns the value of the given attribute, or null if the attribute is not set. Note: This function requires 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: attribute() or attribute( attr, value ) Parameters: attr: This parameter holds the attribute name which need to set. value: This parameter holds the value to assign to that attribute. Return Value: This function returns the value of attribute in string format. Below example illustrates the attribute() function in p5.js: Example: javascript function setup() { // Canvas size 400*400 createCanvas(400, 200); // Set background color background('green'); // Create an input element var input_val = createInput(''); // Set the attribute and its value input_val.attribute('value', 'Welcome to GeeksforGeeks'); // Set the position of div element input_val.position(60, 80); // Set width of input field input_val.style('width', '250px'); // Set font-size of input text input_val.style('font-size', '20px'); } Output: Comment More infoAdvertise with us Next Article p5.js draw() Function J jit_t Follow Improve Article Tags : JavaScript Web Technologies JavaScript-p5.js Similar Reads p5.js char() function The char() function in p5.js is used to convert the given string or number value into its corresponding single-character string representation. If the input parameter is a string value then at first it gets converted into its integer equivalent internally after that its single-character string is re 3 min read p5.js draw() Function The draw() function is called after setup() function. The draw() function is used to executes the code inside the block until the program is stopped or noLoop() is called. If the program does not contain noLoop() function within setup() function then draw() function will still be executed once befor 1 min read Backbone.js attributes View Backbone.js attributes view are nothing but a hash of attributes which are set as HTML DOM element attributes on the view's el. For example, (id, class, data-properties, etc.), or in other cases, a function that returns a hash. Syntax: view.attributes Parameters: View: It is a class under Backbone w 2 min read p5.js str() function The str() function in p5.js is used to convert the given boolean, string and number value into its string representation. Syntax: str(value) Parameters: This function accepts single parameter value which is to be converted into its string representation. This value might be integer, float, string, b 2 min read p5.js red() function The red() function in p5.js is used to extract the red value from a color or pixel array. Syntax: red(c) Parameters: This function accepts single parameter c which stores the p5.Color object, color components, or CSS color. Below programs illustrates the red() function in p5.js: Example 1: This exam 2 min read Backbone.js attributes Model The Backbone.js attributes model is used to define the property of the given model and uses the update/change the attributes using set() method. Syntax: Backbone.Model.attributes Parameters: It does not accept any parameter. Example 1: In this example, we will set the book with 1 attribute using the 2 min read Like