title: removeClass if addClass clicked?
body: <p>If a new ranking is clicked how can we automatically declick the previous click?</p>
  
  <pre><code>&lt;%= f.hidden_field(:ranking, id: 'ranking') %&gt;
  &lt;%= image_tag('4.png', data: { ranking: 4 }, class: 'image-clicker') %&gt;
  &lt;%= image_tag('3.png', data: { ranking: 3 }, class: 'image-clicker') %&gt;
  &lt;%= image_tag('2.png', data: { ranking: 2 }, class: 'image-clicker') %&gt;
  &lt;%= image_tag('1.png', data: { ranking: 1 }, class: 'image-clicker') %&gt;
  
  &lt;script&gt;
    $('.image-clicker').click(function() {
      $('#ranking').val($(this).data('ranking'));
      if ($('#ranking').hasClass('clicked')){ #Conditional doesn't work. If user clicks on second image the first image will stay clicked
        $('.clicked').removeClass('clicked')
      }else{
        $(this).addClass('clicked');
      }
    });
  &lt;/script&gt;
  </code></pre>
  
  <p>I tried to incorporate the answers from here: <a href="https://stackoverflow.com/questions/18468177/removeclass-if-it-exists">removeClass() if it exists</a>, but they didn't work for me.</p>