-1
The thing is, I’m a layman at programming, but I’m doing a website, and in this case, all you have to do is pop up, so you can book an appointment at a hair salon. I am following the following video tutorial: "https://www.youtube.com/watch?v=fu-enUG2VEE".
I’ve done the HTML and CSS part, defining the classes, id, and stylizations, but in this part of Javascript I’m having this error of Cannot read property 'classList' of null at iniciaModal
I followed the tutorial perfectly, of course respecting the way of my project, type, my CSS and Javascript are external HTML, all the files I use in the site project, are in the same folder and linked in HTML code.
I will briefly put the code part:
HTML
<head>
<script type="text/javascript" src="index2.js"></script>
</head>
<body>
<div id="modal-promocao" class="modal-container">
<div class="modal">
<button class="fechar">X</button>
<h3>Solicitação de Agendamento</h3>
<form>
<input type="text" placeholder="Nome">
<input type="text" placeholder="Número">
<button>Manhã</button><button>Tarde</button>
<input type="button" value="Enviar">
</form>
</div>
</div>
</body>
Javascript
function iniciaModal(modalID) {
const modal = document.getElementById(modalID);
modal.classList.add('mostrar');
}
iniciaModal('modal-promocao');
If anyone can explain it to me in a simple way, because I’m not very familiar with all the codes. The goal is just to make this pop-up work properly and understand why this error of Cannot read property 'classList' of null at iniciaModal
.
I’m still very new in programming, so I didn’t understand very well what this DOM means a lot, but it depends on my studies, someday I learn straight, I put the script before closing the body and solved the problem, thanks for helping Luiz!
– Ramon Rossini
@Ramonrossini, this question may help you understand: What is DOM, Render Tree and Node?
– Luiz Felipe