Loop


Bug fixing DOM manipulation Public

Hard  

15min


Function appendChildren should add a new child div to each existing div. New divs should be decorated by calling decorateDiv.

For example, after appendChildren is executed, the following divs:

  <div id="a">
    <div id="b">
    </div>
  </div>

should take the following form (assuming decorateDiv does nothing):

  <div id="a">
    <div id="b">
      <div></div>
    </div>
    <div></div>
  </div>

The code below should do the job, but for some reason it goes into an infinite loop. Fix the bugs.

ECMAScript 5.1, jQuery v1.11.0 (available as $)
   

  •   Example case: Exception
  •   Appending divs: Exception