$( document ).ready(function() { $("#have_read_form").ajaxForm(); }); $("#have_read_cb").on("change", function() { $(this).closest("form").submit(); }); $("#shelf-actions").on("click", "[data-shelf-action]", function (e) { e.preventDefault(); $.get(this.href) .done(() => { const $this = $(this); switch ($this.data("shelf-action")) { case "add": $("#remove-from-shelves").append(` ${this.textContent}`); break; case "remove": $("#add-to-shelves").append(`
  • ${this.textContent}
  • `); break; } this.parentNode.removeChild(this); }) .fail((xhr) => { const $msg = $("", { "class": "text-danger"}).text(xhr.responseText); $("#shelf-action-status").html($msg); setTimeout(() => { $msg.remove(); }, 10000); }); });