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

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

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 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!