Skip to content

Instantly share code, notes, and snippets.

@tararoutray
Created October 9, 2022 02:02
Show Gist options
  • Save tararoutray/6474823cf93429fc56835eaac7645578 to your computer and use it in GitHub Desktop.
Save tararoutray/6474823cf93429fc56835eaac7645578 to your computer and use it in GitHub Desktop.
const selectRadioCard = (cardNo) => {
/**
* Loop through all radio cards, and remove the class "selected" from those elements.
*/
const allRadioCards = document.querySelectorAll(".radio-card");
allRadioCards.forEach((element, index) => {
element.classList.remove(["selected"]);
});
/**
* Add the class "selected" to the card which user has clicked on.
*/
const selectedCard = document.querySelector(".radio-card-" + cardNo);
selectedCard.classList.add(["selected"]);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment