Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Accordion for WordPress Lay Theme
Button Link: #akkordeon_1
HTML Klasse: akkordeon_1
<!-- Custom HTML at bottom -->
<script>
window.laytheme.on( "newpageshown", function( layoutObj, type, obj ) {
var akkordeonActiveClassName = "akkordeon--active",
akkordeonBtnEls = document.querySelectorAll("[href^='#akkordeon_']");
akkordeonBtnEls.forEach( function( akkordeonBtnEl, i ) {
var akkordeonChildClass = akkordeonBtnEl.getAttribute("href").replace("#", ""),
akkordeonChildEls = document.querySelectorAll( "." + akkordeonChildClass );
akkordeonBtnEl.addEventListener( "click", function( e ) {
akkordeonChildEls.forEach( function( akkordeonChildEl, i ) {
if (akkordeonChildEl.classList.contains(akkordeonActiveClassName)) {
akkordeonChildEl.classList.remove(akkordeonActiveClassName);
} else {
akkordeonChildEl.classList.add(akkordeonActiveClassName);
}
} );
} );
} );
} );
</script>
/* Custom CSS */
[class*="akkordeon_"] {
display: none !important;
}
.akkordeon--active {
display: block !important;
}
@iciio
Copy link

iciio commented Mar 4, 2021

<3!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment