Public/assets/scripts/edit-post.js
//Remove textarea and submitbutton to cancel the edit mode
Remove textarea and submitbutton to cancel the edit mode
Remove textarea and submitbutton to cancel the edit mode
function quitEditMode(event) {
  event.currentTarget.textContent = "Edit";
  editButtons.forEach(editButton => {
    editButton.addEventListener("click", editMode);
    editButton.removeEventListener("click", quitEditMode);
    editButton.classList.remove("cancel");
  });
  const form = event.currentTarget.parentElement;
  form.classList.remove("edit-mode");
  const description =
    event.currentTarget.parentNode.parentNode.nextElementSibling;
  description.classList.toggle("hide");
  const submitButton = document.querySelector(".save");
  submitButton.parentNode.removeChild(submitButton);
  const textarea = document.querySelector(".description-textarea");
  textarea.parentNode.removeChild(textarea);
}
function quitEditMode ( event ) { event . currentTarget . textContent = "Edit" ; editButtons . forEach ( editButton => { editButton . addEventListener ( "click" , editMode ) ; editButton . removeEventListener ( "click" , quitEditMode ) ; editButton . classList . remove ( "cancel" ) ; } ) ; const form = event . currentTarget . parentElement ; form . classList . remove ( "edit-mode" ) ; const description = event . currentTarget . parentNode . parentNode . nextElementSibling ; description . classList . toggle ( "hide" ) ; const submitButton = document . querySelector ( ".save" ) ; submitButton . parentNode . removeChild ( submitButton ) ; const textarea = document . querySelector ( ".description-textarea" ) ; textarea . parentNode . removeChild ( textarea ) ; }
Remove textarea and submitbutton to cancel the edit mode
Remove textarea and submitbutton to cancel the edit mode
//Change the button back to contain "edit" and add editMode function to eventlistener //Remove edit-mode class from form // Show the description paragraph again, and remove textarea and save button from the form