Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

68
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!