How to add an object to the DOM tree? (not a div node), namely an object (within which the css of the corresponding div'a is already written).

I try appendChild , but nothing turns out ...

Here is the code:

 var little = document.getElementById('littleField'); //создаём Π΄ΠΈΠ² little.classList.add('little'); function Day(date, conteiner) { //конструктор ΠΎΠ±ΡŠΠ΅ΠΊΡ‚Π° this.date = date; this.conteiner = conteiner; } Day.prototype.generateDate = function () { //ΠΏΡ€ΠΎΡ‚ΠΎΡ‚ΠΈΠΏ ΠΎΠ±ΡŠΠ΅ΠΊΡ‚Π° var day1 = document.createElement('day1'); day1.classList.add('day'); conteiner.appendChild(day1); //ΠΏΠΎΠΏΡ‹Ρ‚ΠΊΠ° Π°ΠΏΠΏΠ΅Π½Π΄ΠΈΠ½Π³Π°))) } var array = []; //ΠΎΠ±Π΅ΠΊΡ‚Ρ‹ Π² массив ΠΈ вставка Π² Π΄ΠΈΠ². while (i <= 29) { var i = 0; var obj = new Day(i, little); //создаём ΠΎΠ±ΡŠΠ΅ΠΊΡ‚ array[i] = obj; i++; } 
  • How to address the property of the object created by the designer? conteiner.appendChild (day1); // attempt to attach))) - user220409

1 answer 1

Running version:

  var little = document.getElementById('littleField'); //создаём Π΄ΠΈΠ² little.classList.add('little'); function Day(date, conteiner) { //конструктор ΠΎΠ±ΡŠΠ΅ΠΊΡ‚Π° this.date = date; this.conteiner = conteiner; } Day.prototype.generateDate = function () { //ΠΏΡ€ΠΎΡ‚ΠΎΡ‚ΠΈΠΏ ΠΎΠ±ΡŠΠ΅ΠΊΡ‚Π° var day1 = document.createElement('div'); day1.classList.add('day'); this.conteiner.appendChild(day1); //ΠΏΠΎΠΏΡ‹Ρ‚ΠΊΠ° Π°ΠΏΠΏΠ΅Π½Π΄ΠΈΠ½Π³Π°))) } var array = []; //ΠΎΠ±Π΅ΠΊΡ‚Ρ‹ Π² массив ΠΈ вставка Π² Π΄ΠΈΠ². var i = 0; while (i <= 29) { var obj = new Day(i, little); //создаём ΠΎΠ±ΡŠΠ΅ΠΊΡ‚ obj.generateDate() array[i] = obj; console.log(array[i]); i++; } 
  • Have you ever worked as a manager? Just your answer reminded me of this one :) - user220409
  • yes it was :) - L. Vadim
  • why minus something? - L. Vadim
  • For personal and professional reasons. If in simple words, you wrote a complete garbage. - user220409
  • Well, this is your choice, thanks :) - and how would you write? Just interesting to see - L. Vadim