Categories
JavaScript Answers

How to remove style on an element with JavaScript?

Spread the love

Sometimes, we want to remove style on an element with JavaScript.

In this article, we’ll look at how to remove style on an element with JavaScript.

How to remove style on an element with JavaScript?

To remove style on an element with JavaScript, we can set the styles to null.

For instance, we write

const element = document.getElementById("sample_id");

element.style.width = null;
element.style.height = null;

to select the element with getElementById.

Then we set the width and height styles to null to remove the width and height styles of the element.

Conclusion

To remove style on an element with JavaScript, we can set the styles to null.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

One reply on “How to remove style on an element with JavaScript?”

Leave a Reply

Your email address will not be published. Required fields are marked *