How to use the setProperty method In Javascript
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: In this example, we have used CSS removeProperty.
html
<!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" > w3wiki </ 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:
How to remove CSS property using JavaScript?
To remove CSS property using JavaScript, we have different methods. In this article, we will learn how to remove CSS property using JavaScript.
Below are the Methods used to remove CSS property using JavaScript:
Table of Content
- Using CSS removeProperty
- Using the setProperty method
Contact Us