I have this code and I get this error
Uncaught TypeError: Cannot set property 'onclick' of undefined
when I click on opening the modal I get the error, but I give it another click and it will be done with the error, but the idea is that there will be the modal with the first click
<button type="button" id="myBtn3" onclick="modal3()" class="btn btn-default">SOLICITAR DIAGNÓSTICO GRATUITO AHORA</button>
function modal3(){
var modal3 = document.getElementById('myModal-3');
var btn3 = document.getElementById("myBtn3");
var span = document.getElementsByClassName("close")[0];
btn3.onclick = function() {
modal3.style.display = "block";
}
span.onclick = function() {
modal3.style.display = "none";
}
window.onclick = function(event) {
if (event.target == modal) {
modal3.style.display = "none";
}
}
}
I appreciate your help