Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

75
Vistas
Clear inline style after reset

How do I remove the inline style which is added by JavaScript?

For example: if people click the button, the marginTop of div#test will be 30px, but what if I want to remove the inline style instead of resetting it to another value like 0?

I do not want to add a class to that element and remove it because it's not suitable in my use case.

const elm = document.querySelector('#test')

function change() {
  elm.style.marginTop = '30px';
}
#test {
  width: 150px;
  height: 60px;
  background-color: blue;
}
<div id="test"></div>
<button onclick="change()">Change</button>

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

either set as empty string

elm.style.marginTop = '';

or to remove the complete attribute use

removeAttribute

elem.removeAttribute('style');
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda