p5.js | removeAttribute() Function
Last Updated :
21 Jun, 2021
The removeAttribute() function is an inbuilt function which is used to remove an attribute on the specified element.
This function requires p5.dom library. So add the following line in the head section of the index.html file.
javascript
<script language= "javascript"
type= "text/javascript" src= "path/to/p5.dom.js" >
</script>
|
Syntax:
removeAttribute( attr )
Parameters: This function accepts single parameter attr which holds the value of attribute which need to removed.
Below example illustrates the removeAttribute() function in p5.js:
Example:
javascript
var input_val;
var checkbox;
function setup() {
createCanvas(400, 200);
background( 'green' );
input_val = createInput( 'Welcome to GeeksforGeeks' , true );
input_val.position(30, 80);
input_val.style( 'width' , '250px' );
input_val.style( 'font-size' , '20px' );
input_val.style( 'margin-left' , '50px' );
checkbox = createCheckbox( 'enable' , true );
checkbox.changed(enableInputText);
}
function enableInputText() {
if ( this .checked()) {
input_val.removeAttribute( 'disabled' );
}
else {
input_val.attribute( 'disabled' , '' );
}
}
|
Output:
- Click to enable the Checkbox:
- Click to disable the Checkbox:
Share your thoughts in the comments
Please Login to comment...