How can I fade out then remove a section after clicking on it in WordPress ? This is the code that I used in brackets which worked , but doesn't work for WordPress.I use the theme Oceanwp , which allows me to add CSS and JavaScript code easily , but if you have a better idea on how to achieve this result , I would highly appreciate it. You can see exactly what I want to achieve with this website https://www.alphafx.co.uk/ after you click on the letter A then on any button(CORPORATE or INSTITUTION) , the current section fades away smoothly
document.querySelector('.list').addEventListener("click", function(e) {
if (e.target.localName === "section") {
//Add CSS hide and animate with fade out
var currentCSS = this.className;
this.className = currentCSS + 'hide';
var removeTarget = e.target.parentNode.parentNode;
setTimeout(function() {
removeTarget.parentNode.removeChild(removeTarget);
}, 1000);
};
});
.hide {
opacity: 0;
}
.top {
transition: 1s linear all;
background-color: blue;
height: 100vh;
}
section {
background-color: green;
}
<div class="top">
<section class="list">This is a section</section>
</div>