How to use CSS removeProperty In Javascript

The CSStyleDeclaration.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: In this example, we have used CSS removeProperty.

html




<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <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 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:

How to remove CSS property using JavaScript?

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

Similar Reads

Method 1: Using CSS removeProperty

The CSStyleDeclaration.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....

Method 2: Using the setProperty method

...

Contact Us