-4

I would like to change a HTML class with JavaScript!

    <div class="not-submitted-check" data-submit-check>
     <i class="fas fa-check-circle"></i> Thank you for contacting us,
     <button type="button" class="close"><i class="fas fa-times"></i></button>
    </div>

I want the div class to change when i press the submit button

<button type="submit" class="submit" data-submit-button>submit</button>

const submitButton = document.querySelector("[data-submit-button]");
submitButton.addEventListener("submit", handleSubmit);

I want to create a function where the moment i press the button the classes change one with another

MrHook
  • 3
  • 2
  • 5
    What have you already tried and/or researched? – PM 77-1 Mar 09 '21 at 21:26
  • 3
    Does this answer your question? [How to add/remove a class in JavaScript?](https://stackoverflow.com/questions/6787383/how-to-add-remove-a-class-in-javascript) – JTorleon Mar 09 '21 at 21:29
  • 1
    This answer is easily found on internet, next time before you ask a question do a search, please. – Blackjack Mar 09 '21 at 21:31

1 Answers1

0

Use this:

element.classList.remove("oldclass");
element.classList.add("newclass");
Blackjack
  • 1,322
  • 1
  • 16
  • 21