title: How to toggle data attribute with jQuery?
body: <p>I need to toggle between two possible values for a data attribute.</p>
  
  <p>If <code>data-state</code> is equal to <code>enabled</code> then I want to change it to <code>disabled</code> and vice versa.</p>
  
  <pre><code>$('.sites .state').on('ajax:success', function(data, status, xhr) {
     var site = $(this).parents('article').first();
  
     if (site.data('state') == 'enabled') {
       site.attr('data-state', 'disabled');
     } else {
       site.attr('data-state', 'enabled');
     }
  });
  </code></pre>
  
  <p>NOTE: I needed to change the DOM element and <a href="https://stackoverflow.com/a/9768213/147586">to my knowledge</a>, I can't use <code>data</code> to do that (hence the use of <code>attr</code>).</p>