I created a header with two modals using html, css, and javascript. Linking these within the html document.
I've decided to create a wordpress theme, and will include the mentioned header. I am following the Theme Developer Handbook by Wordpress, and have simply copied and pasted the code where it needs to go in header.php etc.
As it is more proper to do so, I created a functions.php file and used wp_enqueue_script to add my javascript. It is not working. When I say not working, I mean it doesn't even load onto the page.
functions.php
<?php
function k9stormdomestictheme_script_enqueue() {
wp_enqueue_style( 'k9stormdomesticstyle', get_stylesheet_uri() );
wp_enqueue_script( 'k9stormdomesticscript', get_template_directory_uri() . '/js/script.js', array (), 1.1, true);
}
add_action('wp_enqueue_scripts', 'k9stormdomestictheme_script_enqueue');
?>
index.php
<?php
get_header();
get_footer();
?>
script.js
var modalBtns = [...document.querySelectorAll(".button")];
modalBtns.forEach(function(btn){
btn.onclick = function() {
var modal = btn.getAttribute('data-modal');
document.getElementById(modal).style.display = "block";
}
});
var closeBtns = [...document.querySelectorAll(".close")];
closeBtns.forEach(function(btn){
btn.onclick = function() {
var modal = btn.closest('.modal');
modal.style.display = "none";
}
});
window.onclick = function(event) {
if (event.target.className === "modal") {
event.target.style.display = "none";
}
}
I really appreciate any help. Thank you very much!