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() { // Canvas size 400*400 createCanvas(400, 200); // Set background color background( 'green' ); // Create an input element with its value input_val = createInput( 'Welcome to neveropen' , true ); // Set the position of div element input_val.position(30, 80); // Set width of input field input_val.style( 'width' , '250px' ); // Set font-size of input text input_val.style( 'font-size' , '20px' ); // Set margin property input_val.style( 'margin-left' , '50px' ); // Create a checkbox checkbox = createCheckbox( 'enable' , true ); // Set the status of checkbox checkbox.changed(enableInputText); } function enableInputText() { if ( this .checked()) { // Re-enable the button input_val.removeAttribute( 'disabled' ); } else { // Disable the button input_val.attribute( 'disabled' , '' ); } } |
Output:
- Click to enable the Checkbox:
- Click to disable the Checkbox: