p5.js | removeAttribute() Function

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.

filter_none

edit
close

play_arrow

link
brightness_4
code

<script language="javascript" 
    type="text/javascript" src="path/to/p5.dom.js">
</script>

chevron_right


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:

filter_none

edit
close

play_arrow

link
brightness_4
code

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 GeeksforGeeks', 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 propery
    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', '');
   }
 }

chevron_right


Output:

  • Click to enable the Checkbox:
  • Click to disable the Checkbox:

full-stack-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.