There is a source code snippet:

<tr id="file_theme_estimates_rus"> <td><span class="five">5</span></td> <td></td> <td><span class="two">2</span></td> <td><span class="three">3</span></td> <td></td> <td></td> </tr> <tr> <td id="file_estimates_rus"></td> </tr>

There is a broken Javascript function:

document.getElementById("file_estimates_rus").textContent = document.getElementById("file_theme_estimates_rus").getElementsByTagName("span").textContent;

What should I do to make the Javascript function work? All span elements need to appear in the <td id="file_estimates_rus">...</td> . Those. in this case, after executing the Javascript function, it should turn out like this:

<tr id="file_theme_estimates_rus"> <td><span class="five">5</span></td> <td></td> <td><span class="two">2</span></td> <td><span class="three">3</span></td> <td></td> <td></td> </tr> <tr> <td id="file_estimates_rus"><span class="five">5</span><span class="two">2</span><span class="three">3</span></td> </tr>

Please write a Javascript function to help me do this.

  • You have already written almost 50 questions. Maybe it's time to learn how to format the code? - Athari

1 answer 1

 var a = document.getElementById("file_estimates_rus"), b = document.getElementById("file_theme_estimates_rus").getElementsByTagName("span"); for (var i = 0; i < b.length; i++) { a.innerHTML += b[i].outerHTML; } 
  • Is it possible to make the numbers go in a different order? Those. here it turns out to be “3 2 5”, but can you make “5 2 3”? - nick
  • Here it turns out "5 2 3". See for yourself jsfiddle.net/wzwewr6d/1 - ArchDemon
  • So all the same, how to do not "5 2 3", but "3 2 5"? - nick