方法1(CSS+JavaScript)
CSS
1ul:not(.show) {
2 visibility: hidden;
3}
JavaScript
1document.addEventListener('DOMContentLoaded', function() {
2 document.querySelector('h2').addEventListener('click', function(event) {
3 document.querySelector('ul').classList.toggle('show');
4 }, false);
5}, false);
https://developer.mozilla.org/ja/docs/Web/API/Element/classList
方法2(HTML+JavaScript)
HTML
1 <ul hidden="hidden">
JavaScript
1document.addEventListener('DOMContentLoaded', function() {
2 document.querySelector('h2').addEventListener('click', function(event) {
3 document.querySelector('ul').toggleAttribute('hidden');
4 }, false);
5}, false);
IE 不可
https://developer.mozilla.org/en-US/docs/Web/API/Element/toggleAttribute