for my toast notifications I create a div container called "toastArea". So when I write in my HTML file
<div class="toastArea"></div>
everything is fine. But I want to create it dynamically by using JS. So in my toast controller I write
class ToastController { // class for toast notifications
constructor() {
this.CreateToastArea(); // create a div for every toasts
}
CreateToastArea() {
var area = document.createElement("div"); // create div
area.classList.add("toastArea"); // add a class to the div
document.body.appendChild(area); // append div to the body
}
}
but when the constructor calls the function it says
Cannot read property 'appendChild' of null
but the variable "area" is not null. The div got created correctly.
I don't get what's wrong there..