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

139
Visualizações
Toggle switch display on selected

I would like to display creating product in admin section sub categories in tree only when selected else closed in woocommerce product categoreis. How can I achieve this ? Presently it appears like this. Tried css but didn't work.

<li id="tire_sizes-52"><label class="radiall"><input value="52" type="checkbox" name="tax_input[tire_sizes][]" id="in-tire_sizes-52"> 145</label><ul class="children">

<li id="tire_sizes-62"><label class="radiall"><input value="62" type="checkbox" name="tax_input[tire_sizes][]" id="in-tire_sizes-62"> 65</label>    <ul class="children">

<li id="tire_sizes-87"><label class="radiall"><input value="87" type="checkbox" name="tax_input[tire_sizes][]" id="in-tire_sizes-87"> 15</label></li>
    </ul>
</li>
</ul>
</li>

I want it closed and open only if selected

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

0


// if a checkbox has a child, add a css class="has-children"
// select them
const parents = document.querySelectorAll('.has-children')

const caches = parents.map(() => ([]))

function clear(parent) {
 const id = parent.getAttribute('id');
 const ul = parent.querySelector('.children');
 ul.css.display = 'none'; // hide from the DOM
 // you may also need to remove it from the DOM
 /*
 children = [];
 while (parent.firstChild) {
  const firstChild = parent.firstChild
  parent.removeChild(firstChild)
  caches[id].push(firstChild);
 }*/
}

// inital setup
parents.forEach(function (parent) {
 const id = parent.getAttribute('id');
 clear(parent);
 
 // setup listen for changes to parents
 parent.addEventListener('change', function() {
   let child;
   if (child = parent.querySelector('children')) {
    if (child.css.display === 'block') {
     clear(parent)
    } else {
     //caches[this.getAttribute('id')].forEach(c => 
     //  this.appendChild(c)
     delete caches[this.getAttribute('id')]
     const ul = parent.querySelector('.children');
     ul.css.display = 'block'; // show from bom
    }
 });

})

something like this. Checkout jquery it may be easier

If this is right, please give me points, i'm a nooob

I haven't executed this code , so it will need your attentions. but that is the essance of it. As I say. look into jquery. This can be accomplished in 3 lines of code.

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