Comes json. And in the HTML markup, there are already 5 tags. It is necessary that each value be recorded in each tag in order. For example: <h1> ДСнис</h1> , <h1>Николай</h1> ,<h1> Владислав</h1> ,<h1> Π•Π²Π³Π΅Π½ΠΈΠΉ</h1> , <h1>АлСксандр</h1> .

I tried through apend () but for some reason I have the last element recorded in the tag's mustache.

  $('h1').each(function(index, value){ var name = value[index].name; $(this).text(name); }); 

Here is json himself:

 { "1": { "name": "ДСнис" }, "2": { "name": "Николай" }, "3": { "name": "Владислав" }, "4": { "name": "Π•Π²Π³Π΅Π½ΠΈΠΉ" }, "5": { "name": "АлСксандр" } } 

How to syntactically spell such a crawl of elements?

  • Give your javascript, otherwise it is not clear what is wrong with you - sercxjo
  • Show HTML please - naXa
  • @SergeEsmanovich here is not used Angular - naXa
  • @naXa can also write a script based on the search attribute ng-repeat parsing and inserting the same element. Then simply connecting the script will be able to build similar structures. - Serge Esmanovich

1 answer 1

Wrap the tags in <div class="top-html-tag"></div> . Go through the loop and use the DOM functions:

 var names = document.getElementsByClassName("top-html-tag")[0].childNodes; var items = json.items; for (var i = 0; i < items.length && i < names.length; ++i) { names[i].innerHTML = items[i].name; } 

getElementsByClassName does not work in IE below version 9. If you want to support older browsers, better use jQuery.

  • Your method creates markup, and how to make it inserted into existing tags? - Dementiy1999
  • @ Dementiy1999 and now? Not sure if the code works, but hopefully the idea is clear. - naXa