I'm going to put this JavaScript code in the <button onclick"">
I don't understand why it does not work
if possible, please modify the code
<button onclick='document.getElementsByClassName("city");for (var i = 0; i < x.length; i++) {x[i].style.display = "none";}'>Hide elements</button>
<h2 class="city">London</h2>
<p>London is the capital of England.</p>
<h2 class="city">Paris</h2>
<p>Paris is the capital of France.</p>
<h2 class="city">Tokyo</h2>
<p>Tokyo is the capital of Japan.</p>