Em um exercício,estava tentando criar uma tabela através da DOM utilizando template string e o comando innerHTML
Local aonde quero inserir os td
<tr id="boletinAluno">
</tr>
Criando o aluno
function cadastrarAluno(e){
let nome = document.querySelector('#nome').value
let nota1 = document.querySelector('#nota1').value
let nota2 = document.querySelector('#nota2').value
let nota3 = document.querySelector('#nota3').value
let aluno = new Aluno(nome,nota1,nota2,nota3)
montarLinha(aluno);
}
MontarLinha
function montarLinha(aluno){
let content = `
<td>${aluno.nome}</td>
<td>${aluno.nota1}</td>
<td>${aluno.nota2}</td>
<td>${aluno.nota3}</td>
<td>${aluno.getMedia}</td>
`
boletin = document.querySelector('#boletinAluno').innerHTML+=content;
}
ERRO
index.html:89 Uncaught TypeError: Cannot read property 'innerHTML' of null
at montarLinha (index.html:89)
at cadastrarAluno (index.html:75)
at HTMLInputElement.onclick (index.html:39)
montarLinha @ index.html:89
cadastrarAluno @ index.html:75
onclick @ index.html:39
document.querySelector('#boletinAluno')
está retornandonull
, verifica se tua função não está antes do HTML que criar esse elemento.