p5.js | attribute() Function
Last Updated :
27 Aug, 2019
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:
function setup() {
createCanvas(400, 200);
background( 'green' );
var input_val = createInput( '' );
input_val.attribute( 'value' , 'Welcome to GeeksforGeeks' );
input_val.position(60, 80);
input_val.style( 'width' , '250px' );
input_val.style( 'font-size' , '20px' );
}
|
Output:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...