Toggle between two elements

Marko Krstić
22 Jul 2022
<div class="toggle-wrap">
  <div id="box-1" class="box active">Click me</div>
  <div id="box-2" class="box">Click me again</div>
</div>
(function ($) {
  $(function () {
    $(".toggle-wrap").click(function () {
      $(this).find(".box").toggleClass("active");
    });
  });
})(jQuery);

Was this article helpful?

Tags

Categories

Never miss new post again

Subscribe and get list of new posts in your inbox

Click to Copy