Method 1: Using CSS removeProperty: The CSSStyleDeclaration.removeProperty() method is used to remove a property from a style of an element. The style of the element is selected by going through the styleSheets array and selecting the cssRule. The removeProperty method can then be specified with the property to be removed.
Syntax:
element.removeProperty('property')
Example-1:
<!DOCTYPE html> <html> <head> <title> How to remove CSS property using JavaScript? </title> <style> .elem { color: green; font-size: 3rem; text-decoration: underline; } </style> </head> <body> <h1 style="color: green"> GeeksForGeeks </h1> <b> How to remove CSS property using JavaScript? </b> <div class="elem">Hello World!</div> <p> Click on the button below to remove the text decoration of the element </p> <button onclick="removeProperty()"> Remove text-decoration property </button> <script> function removeProperty() { element = document.styleSheets[0].cssRules[0].style; element.removeProperty('text-decoration'); } </script> </body> </html> |
Output:
- Before clicking the button:
- After clicking the button:
Method 2: Using the setProperty method: The CSSStyleDeclaration.setProperty() method can be used to set the required property of the style. The element of which the property has to be removed is selected and this property is applied to its style property. Setting this property to ‘initial’ resets the property to its initial value, removing any effect of the property.
Syntax:
element.style.setProperty('color', 'initial')
Example:
<!DOCTYPE html> <html> <head> <title> How to remove CSS property using JavaScript? </title> <style> .elem { color: green; font-size: 3rem; text-decoration: underline; } </style> </head> <body> <h1 style="color: green"> GeeksForGeeks </h1> <b> How to remove CSS property using JavaScript? </b> <div class="elem">Hello World!</div> <p> Click on the button below to remove the text color of the element </p> <button onclick="removeProperty()"> Remove color property </button> <script> function removeProperty() { element = document.querySelector('.elem'); element.style.setProperty('color', 'initial'); } </script> </body> </html> |
Output:
- Before clicking the button:
- After clicking the button:
Recommended Posts:
- How to remove style added with .css() function using JavaScript?
- How to remove CSS style of <style> tag using JavaScript/jQuery ?
- How to remove a property from JavaScript object ?
- Remove border from IFrame using CSS
- How to remove underline for anchors tag using CSS?
- How to remove indentation from an unordered list item using CSS?
- How to remove underline from a:before using CSS ?
- How to remove all line breaks from a string using JavaScript?
- How to remove the table row in a table using JavaScript ?
- How to remove time from date using JavaScript ?
- How to remove an HTML element using JavaScript ?
- How to remove duplicates from an array of objects using JavaScript ?
- How to remove all inline styles using JavaScript/jQuery ?
- How to remove spaces from a string using JavaScript ?
- Remove the Chrome's "No file chosen option" from a file input using JavaScript
- How to remove all Non-ASCII characters from the string using JavaScript ?
- How to remove object from array of objects using JavaScript ?
- How to remove underline from link using JavaScript ?
- How to remove “disabled” attribute from HTML input element using JavaScript ?
- How to Remove Column from HTML Table using JavaScript ?
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.


