DEV Community

Cover image for How to remove CSS Property using javascript?
Tanwi Kumari
Tanwi Kumari

Posted on

3 1

How to remove CSS Property using javascript?

<!DOCTYPE html>
<html>
<head>
<style>
#myDIV {
  background-color: coral;
  border: 1px solid;
  padding: 50px;
  color: white;
}
</style>
</head>
<body>

<div id="myDIV">This div element has an onmousemove event handler that displays a random number every time you move your mouse inside this orange field.
  <p>Click the button to change the color of text.</p>
  <button onclick="removeHandler()" id="myBtn">Try it</button>
</div>

<h1 id="demo">Hello everyone</h1>

<script>
document.getElementById("myDIV").addEventListener("mousemove", myFunction);

function myFunction() {
  document.getElementById("demo").style.color = "green";
}

function removeHandler() {
  document.getElementById("demo").style.removeProperty('color');
}
</script>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode

OUTPUT:

1.) Without Click ‘Try It’ button text is ‘green’:

Screenshot (325)

2.) After Click the button remove property call and removes the previous css property of text:

Screenshot (326)

To learn from each other keep sharing and learning!
follow me on Twitter also I post my daily learning and work on Twitter.
https://twitter.com/tk22O9

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

The best way to debug slow web pages cover image

The best way to debug slow web pages

Tools like Page Speed Insights and Google Lighthouse are great for providing advice for front end performance issues. But what these tools can’t do, is evaluate performance across your entire stack of distributed services and applications.

Watch video

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay