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

297
Visualizações
remove css class for elements with specific parent class

So I have this basic structure:

<div class="parentA">
<div class="my special classes">
<!-- stuff -->
</div>
</div>

<div class="parentB">
<div class="my special classes">
<!-- stuff -->
</div>
</div>

How can I strip out the "my special classes" of the parentB div only?

Background. I have added extra classes to the core/blocks in WordPress. I also have custom blocks (eg tabs/accordion) that allow InnerBlocks. If I add core/blocks to these I need to strip out these extra classes.

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Do you want to remove the styling of the class, or remove the class selector from the HTML?

If you want to remove the styling, depending on the complexity of inside the stuff of the second block, you can try

.parentB > .my_special_class1 {
    background-color: inherit;
}

If you want to remove the actual selectors, the simplest way would probably be to remove/change them manually (assuming its not generated code). You could also use Javascript, like

/* Not tested */
function myFunction() {
  var element = document.getElementById("parentB").forEach( e => e.classList.remove("my_special_class1"));
} 

jQuery also has a removeClass method that is handy if you are using jQuery.

https://www.w3schools.com/howto/howto_js_remove_class.asp

about 4 years ago · Juan Pablo Isaza Relatório

0

let specialClasses = ["1", "2", "3"]

let elements = document.querySelectorAll('.parentB .' + specialClasses.join("")) // get them all 

elements.forEach(el => {
    
    el.classList.remove(...specialClasses)
})
about 4 years ago · Juan Pablo Isaza Relatório

0

You can select all those elements with .parentA .my.special.classes, .parentB .my.special.classes and then remove those classes for those elements:

document.querySelectorAll('.parentA .my.special.classes, .parentB .my.special.classes').forEach((el) => {
  el.classList.remove('my', 'special', 'classes')
})
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