V
V
Vladimir Zuev2020-07-19 13:23:16
Google Apps Script
Vladimir Zuev, 2020-07-19 13:23:16

How to fix Cannot read property 'insertAdjacentHTML' of null error?

Hello.
There is a program

function createModel(){
     const models = document.getElementById("#parent");     
     let col_value = document.getElementById("color-result-nameID").textContent;
     let col_text = document.getElementById("color-result-text_col").textContent;
     let profit_ratio = document.getElementById("profit_ratio").value;
     let manager_ratio = document.getElementById("manager_ratio").value;
     let ad_ratio = document.getElementById("ad_ratio").value;
     let n = document.getElementById("color-result-divn").textContent;
     document.getElementById("color-result-divn").textContent = n+1;
    // console.log("manager_ratio = ", manager_ratio);
       const model = `
       <div id = "child-${n+1}"; class="child">
         <div  class="child-1" style="background: ${col_value}">
            <p class="collor-text" style="color: ${col_text}" >Цвет текста<span class="letter" onclick="closeDiv(this.closest('[id^=child]'))">&#215</span></p>
         </div>
         <p style="color: ${col_value}">Кф. прибыли
            <p class="color-kf">${profit_ratio}</p></p>
         <p style="color: ${col_value}">Кф.менеджера</p>
         <p class="color-kf">${manager_ratio}</p></p>
         <p style="color: ${col_value}">Кф. рекламы</p>
         <p class="color-kf">${ad_ratio}</p></p>
      </div>
       `;
    models.insertAdjacentHTML('afterbegin', model);
   };

How to fix Cannot read property 'insertAdjacentHTML' of null error? Please help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mityayka1, 2020-07-19
@vladd56

ID set incorrectly. Try either querySelectorAll or specify an id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question