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

182
Views
Remove nested class in pure JavaScript

I am trying to remove class's some of them are nested.

I know it is possible to remove a class like this:

const coolDiv = document.querySelector('.my-div')
coolDiv.remove('container')

But how would I remove all container classes even the nested ones. For example how would I remove specific class="container" from the example below?

<div class='my-div container'>
    <div class='container'>
        <div class='container'>
        DIV
        </div>
    </div>
</div>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Yes you can with classList.remove

const coolDiv = document.querySelector('.my-div')
coolDiv.classList.remove('container')
<div class='my-div container'>
    <div class='container'>
        <div class='container'>
        DIV
        </div>
    </div>
</div>

Reference:

  • Element.classList

Edit after see for multiple remove:

const coolDivs = document.querySelectorAll('.my-div div')
coolDivs.forEach(coolDiv => {
  coolDiv.classList.remove('container')
});
<div class='my-div container'>
  <div class='container'>
    <div class='container dontdeleteme'>
      <div class='red'>
        DIV
      </div>
    </div>
  </div>
</div>

I add two more case with others class.

Reference:

  • querySelectorAll
  • forEach
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!