<script> function func(){ document.getElementById('div').classList.add('active'); } </script> <button onclick='func()'>Click</button> <div id="div"> This element gets 'active' class. </div>