I have the following method where the main intention is to create a div with a class and use those to create a 'container' for a chart. I've commented where necessary to show what the lines are for.
createChartContainer(chartRef) {
// bring up the grid object
for (var chartDataInTable of this.tableData) {
// if this grid does not have 0 charts
if(chartDataInTable.summary_charts.length != 0) {
// create div
var createDiv = document.createElement('div');
// generate a string I can use as the class name for the newly created div shown above
var randomStringAsClassNames = Math.random().toString(36).substring(7);
// assign the random string as the className for the newly created div
createDiv.className = 'div_' + randomStringAsClassNames;
// chartClassName is defined as a string in data: () => ....
this.chartClassName = createDiv.className;
// non-negotiable as this shows the details of the created chart
var eChart = chartRef.chartElement;
// select the div that we've just created
var eParent = document.querySelector("." + this.chartClassName + "");
eParent.appendChild(eChart);
}
}
},
The problem is that console.log(eParent) returns null and we have the following error: Uncaught TypeError: Cannot read property 'appendChild' of null
If it helps, I'm working with ag-grid to create the chart
So in summary, why is eParent.appendChild(eChart) not working? It's because of document.querySelector("." + this.chartClassName + ""), but it should be correct in terms of how it's laid out?