0

HTML:

<div class="card">
   <div class="card-back bi bi-bicycle">

CSS:

.card-back {
  transform: rotateY(270deg) translateZ(10px);
}
.flipped {
  transform: rotateY(180deg) translateZ(0);
}

Above are my existing code structure; am trying to add the ‘flipped’ class into the ‘card-back’ class ON CLICK in order to flip my card - desired output: <div class="card-back flipped bi bi-bicycle">

Wrote the following function but it didn’t work:

const flipCard = () => {
  $(“.card-back”).on(“click”, (event) => {
    $(event.currentTarget).classList.add(“flipped”);
  });
};
flipCard();

Any help/advice would be appreciated!

2
  • 3
    and are invalid symbols here; use " instead. “but it couldn’t work” isn’t a meaningful problem description. Use the browser console (dev tools) (hit F12), read any errors. Try using your browser’s debug capabilities. The dev tools provide an Inspector / Elements tab. Inspect your elements. What do the applied CSS rules reveal? Commented Nov 7, 2022 at 3:02
  • 1
    $(event.currentTarget).classList classList is not a property of a jquery object. Just use event.currentTarget.classList - or use jquery method $(event.currentTarget).addClass("flipped") Commented Nov 7, 2022 at 6:59

2 Answers 2

1

You can simply do this using jQuery

$(document).on("click", "div.card-back" , function() {
    $(this).addClass("flipped");
});
Sign up to request clarification or add additional context in comments.

Comments

0

This will add the class as you wanted:

const flipCard = () => {
  console.log("click")
  $('.card').on('click', (event) => {
    $('.card-back').toggleClass('flipped');
    console.log("click")
  });
};
flipCard();

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.