Home > Web Front-end > CSS Tutorial > How to Remove a CSS Property from an Element Using JavaScript?

How to Remove a CSS Property from an Element Using JavaScript?

Mary-Kate Olsen
Release: 2024-11-05 11:49:02
Original
1070 people have browsed it

How to Remove a CSS Property from an Element Using JavaScript?

Removing CSS Property Using JavaScript

Is it possible to remove a CSS property of an element using JavaScript? For instance, if you have a CSS property div.style.zoom set to 1.2, how do you remove the zoom property through JavaScript?

There are two options:

Option 1: Using removeProperty Method

The removeAttribute method allows you to remove a style from an element. You can use it as follows:

<code class="javascript">el.style.removeProperty('zoom');</code>
Copy after login

Option 2: Setting Default Value

You can also set the property to its default value:

<code class="javascript">el.style.zoom = "";</code>
Copy after login

This approach will set the zoom level to the default defined in your stylesheets. It only affects the local style of the specific element.

The above is the detailed content of How to Remove a CSS Property from an Element Using JavaScript?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template