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

227
Views
Trying to eliminate children 3-7 from an element, I am looping through the array to eliminate them but it wont work

So first main has only one child which is why I selected the child blades as var blades = main.children[0]; then I am trying to loop through and just eliminate the children within blades from [3] through [7] but for some reason when doing this on the console it won't work.

 function deleteBlades() {
        var main = document.getElementById("id-9a1e3f8f48548d4c2c422b1f92cb749a");
        var blades = main.children[0];
        for (var i = 0; i < blades.length; i++) {
            if( i >= 3 || i <= 7)
                {
                    blades.children[i].remove();
                }
        }
    }
    deleteBlades();

Any ideas on what am I doing wrong?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

in your for loop you are reading blades.length when it is a HTMLElement not array, use blades.children.length instead

 function deleteBlades() {
    var main = document.getElementById("id-9a1e3f8f48548d4c2c422b1f92cb749a");
    var blades = main.children[0];
    for (var i = 0; i < blades.children.length; i++) {
        if( i >= 3 || i <= 7)
            {
                blades.children[i].remove();
            }
    }
}
deleteBlades();
about 4 years ago · Juan Pablo Isaza Report

0

Looks like you got a typo in your loop.

I think what you meant to do is:

for (var i = 0; i < blades.children.length; i++) {
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!