<button class="toggle-button">Toggle button</button>
<div class="content">
  <p>content</p>
  <p>content</p>
  <p>content</p>
  <p>content</p>
  <p>content</p>
</div>
.content {
  width: 10em;
  height: 0;
  padding: 20px 0;
  margin: 20px 0;
  color: white;
  background-color: black;
  text-align: center;
  transition: all .3s ease-out 0s;
}
$('.toggle-button').on('click', function(){
	var content = $('.content')[0];
	content.style.height = content.style.height === content.scrollHeight + 'px'
		? 0
		: content.scrollHeight + 'px';
});

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js