I need to toggle between two possible values for a data attribute.
If data-state is equal to enabled then I want to change it to disabled and vice versa.
$('.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');
}
});
NOTE: I needed to change the DOM element and to my knowledge, I can't use data to do that (hence the use of attr).