NodeList .removeChild removes every other entry - why?

Hi all,

So I’ve been working on a small web-page that allows you to search what car companies own other car companies.

It takes input from the user, checks the input against a JSON formatted array and then appends the “name” and “children” key-value pairs into their appropriate fields in the HTML.

Plnkr public link: http://plnkr.co/edit/17OicY?p=preview

Problem is: When the user submits a second search, the function I’ve created to remove all the previous entries isn’t working properly – it only removes every ~other~ child result and I don’t know why.

To Replicate

  1. Search “fiat”
  2. Search “ford”
  3. Result is: Only half of fiat’s children are removed.

I think there’s something wrong with my removeChildren function’s logic, but I’ve been stuck on it for several hours and I just can’t see what’s wrong with it. :frowning:

Line 97 remove k++

for (var k = 0; k < myNodeList.length;){
1 Like

That was it! Thank you for the assistance, @jenovs :slight_smile: