Simple toggle button javascript

HTML
<div> <img src="https://images.unsplash.com/photo-1495360010541-f48722b34f7d?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1036&q=80"> <br> <button>Cacher</button> </div>
CSS
img { width: 25%; } div { text-align: center; } .active { visibility: hidden; }
JAVASCRIPT
const btn = document.querySelector("button"), img = document.querySelectorAll("img"); const btnToggle = (a, b) => { a.addEventListener("click", () => { b.forEach((el) => el.classList.toggle("active")); }); }; btnToggle(btn, img);
Expand for more options Login