I'd like to do the exact same thing as here Collapsing / hiding figures in R markdown, but instead of one image, I'd like to collapse several consecutive images all at once (using the same single button).
So far the following script, gets the desired result but just for 1 image:
<input type=button class=hideshow></input>
    
<script>
$( "input.hideshow" ).each( function ( index, button ) {
button.value = 'Hide Output';
$( button ).click( function () {
var target = this.nextSibling ? this : this.parentNode;
target = target = target.nextSibling.nextSibling;
if ( target.style.display == 'block' || target.style.display == '' ) {
target.style.display = 'none';
this.value = 'Show Output';
} else {
target.style.display = 'block';
this.value = 'Hide Output';
}
} );
} );
</script>