skip to Main Content
$('.flip-button').each(function() {
    $(this).click(function() {
      $(this).closest('.flip-card-inners').toggleClass('flip-card-active')
    })
  })

I wasn’t able to translate this in vanilla js because I encountered several problems with get element by class

2

Answers


  1. document.querySelectorAll(".flip_button").forEach(element => {
        element.onclick = () => {
            element.closest('.flip-card-inners').classList.toggle("flip-card-active");
        }
    });
    
    Login or Signup to reply.
  2. document
      .querySelectorAll('.flip-button')
      .forEach((element)=> {
        element.addEventListener("click", function(e) {
          // Do your action
        }, false);
      })
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search