1

Using Jquery UI .toggleClass(), I am trying to switch between two CSS classes on selector click but it hasn`t the toggle effect.

    $(".toggle").click(function () {
        $(".archivePosts .columns").removeClass( "large-6" ).addClass( "large-4" );
    });
Mikhail
  • 9,186
  • 4
  • 33
  • 49

1 Answers1

2

The toggleClass method accepts two class names (to be toggled):

$(".toggle").click(function () {
    //$(".archivePosts .columns").removeClass( "large-6" ).addClass( "large-4" );
    $(".archivePosts .columns").toggleClass("large-6 large-4");
});
Mikhail
  • 9,186
  • 4
  • 33
  • 49
skubarenko
  • 154
  • 1
  • 1
  • 6
  • 1
    It should be noted that `toggleClass()` takes *n* class names, not just two. For each class name, it will add that class if the element doesn't already expose it and remove it if it does. My answer under the duplicate focused on two classes because the question itself did. – Frédéric Hamidi Jan 20 '16 at 16:38