Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save wpexplorer/c8d7b232b5c6b90fc8c8c09467bc2b8e to your computer and use it in GitHub Desktop.
Save wpexplorer/c8d7b232b5c6b90fc8c8c09467bc2b8e to your computer and use it in GitHub Desktop.
Open/Close all accordions
// open all accordions with click on button
add_action( 'wp_footer', function() { ?>
<script>
( function( $ ) {
'use strict';
$( document ).ready(function() {
// button has the class = expand-all and the id = btn-expand-all
var expandall = $( '.expand-all' );
var btnExpAll = document.getElementById('btn-expand-all');
//var btnExpAll = document.getElementsByClassName('expand-all');
// get the accordions
var accexp = $( '.vc_tta-accordion .vc_tta-panel' );
//when button is clicked
expandall.click( function() {
// click toggles between class vc_active (open) and no class (closed)
if (btnExpAll.textContent == 'Alle DETAIL-INFORMATIONEN zu dieser Warengruppe EINBLENDEN') {
if ( accexp.val() == ".vc_active" ) {
} else {
accexp.addClass("vc_active");
}
// change the button name (textContent) and color
btnExpAll.textContent = 'Alle DETAIL-INFORMATIONEN zu dieser Warengruppe AUSBLENDEN'
expandall.css('background-color', '#bbbbbb');
}
else{
// change the button name (textContent) and color
accexp.removeClass("vc_active");
btnExpAll.textContent = 'Alle DETAIL-INFORMATIONEN zu dieser Warengruppe EINBLENDEN'
expandall.css('background-color', '#77ac3c');
}
} );
} );
} ( jQuery ) );
</script>
;
<?php } );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment