Search code examples
jquerycoffeescripttoggletoggleclass

jquery toggle class between divs


If I have two div elements where users are to choose between two options.

I'd like to show that the user has clicked on it, so by that when user clicks on an element, the class adds some styling.

Right now I only have the basics down. The user can only choose one of the two elements. So if user already clicks on one element, there's styling. If user decides to click on the other element, the previous click is removed, and then it adds the style on the new click.

  $(".ind").on("click", ->
    $(this).toggleClass("selected")
  );

Hopefully someone can guide me, Thanks!


Solution

  • $(".ind").on "click", ->
        $(this).siblings(".ind").removeClass("selected")
        $(this).toggleClass("selected")