Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

76
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda