Hey guys, hate having to ask help for this one but I’ve been trying to add Javascript enqueue for a few days now but can’t get it to work. I tried different things but this is my latest attempt after re-installing the Child theme and pasting the code in the functions.php file.
​
Also tried adding this (and different types of code) in footer/header with WPCode plugin but nothing happens.
This is what I’m trying to test:
*(mainly trying to figure out how to make JS work at all)*
**HTML:**
<button id=”slide-button”>Click to slide up</button>
<div id=”slide-element”>Slide me up</div>
**JS:**
const button = document.querySelector(“#slide-button”);
const element = document.querySelector(“#slide-element”);
button.addEventListener(“click”, function() {
if (element.style.height === “100px”) {
element.style.height = “0px”;
} else {
element.style.height = “100px”;
}
});
**CSS:**
\#slide-element {
height: 100px;
transition: height 0.5s ease-out;
overflow: hidden;
}
​
Thank you in advance!
[ad_2]
Ok
Ok
Okok hold on, I’m trying:
add_action( ‘wp_enqueue_scripts’, ‘add_slidebuttonjs’ );
function add_slidebuttonjs() {
wp_enqueue_script( ‘slidebutton.js’, get_stylesheet_directory_uri() . ‘/slidebutton.js’, false, ‘1.0’, true );
}
Ok
Ok
Ok