I wrote and copied a small piece of JavaScript for a modal and added it to my main.js file however it doesn't seem to work.
it works on jsfiddle but not on my machine: https://jsfiddle.net/281wr3c6/13/
it just doesn't seem to on my machine for some reason
var modal = document.getElementById("theModal");
var btn = document.getElementById("trigger");
var span = document.getElementsByClassName("close")[0];
btn.onclick = function() {
modal.style.display = "block";
}
div.onclick = function() {
modal.display.style = "none";
}
window.onclick = function(event) {
if (event.target == modal) {
modal.display.style = "none";
}
}
.modal {
display: none;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background: rgba(11,12,12,0.66);
}
.modal.bg {
padding:30px;
float: left;
z-index: 0;
border: none;
border-radius: 0;
margin: 18px 0;
}
.modal .card {
border: 4px solid #dee0e2;
padding:24px;
float: left;
margin: 18px 0;
z-index: 10;
background: #fff;
}
.modal .title {
width: 90%;
display: inline-block;
}
.modal h3 {
margin-top:0;
}
.modal div.buttons button.btn {
margin-bottom: 0!important;
}
.modal div.buttons button.btn.secondary {
margin-left: 0!important;
float: left;
}
.modal div.buttons button.btn.primary {
margin-right: 0!important;
float: right;
}
.modal div.close {
background-image: url("../assets/icons/close.svg");
display: inline-block;
height: 18px;
width: 18px;
padding: 3px;
float: right;
}
<button id="trigger" class="btn primary">Open modal</button>
<div id="theModal" class="cd-box modal bg">
<div class=card>
<div class="title">
<h3>Title</h3>
</div>
<div class="close"></div>
<div class="inside">
<p>This is some content that goes into the modal. The width adjusts according to the content.</p>
</div>
<div class="buttons">
<button class="btn secondary">Exit</button>
<button class="btn primary">Continue with action</button>
</div>
</div>
</div>
I got the code from here: https://www.w3schools.com/howto/howto_css_modals.asp
When I run my code in their fiddle/preview it does work so leads me to think that it's something that my site isn't running?