Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

138
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda