Javascript CSSStyleDeclaration removeProperty Method

Introduction

Remove the color property:

Click the button to remove the color property.

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
#ex1 {/*from w w  w .j a  va2  s.  co m*/
  color: red;
}
</style>
</head>
<body>
<button onclick="myFunction()">Test</button>
<div id="ex1">Some text.</div>
<p id="demo"></p>
<script>
function myFunction() {
  var declaration = document.styleSheets[0].cssRules[0].style;
  var removedvalue = declaration.removeProperty("color");
  document.getElementById("demo").innerHTML = removedvalue;
}
</script>

</body>
</html>

The removeProperty() method removes the specified CSS property from a CSS declaration block.

removeProperty(propertyname);

Parameter Values

ParameterDescription
propertyname Required. A String representing the name of the property to remove

The removeProperty() method returns a String representing the old value of the removed property




PreviousNext

Related