Hi! I’ve been meaning to make a keyboard shortcut for a button on the cards, but the keyboard toggle works on alternate cards (first card it works, second card it doesn’t; third card it works). I’ve modified the code to mirror Anking’s buttons as closely as possible and the card-alternating situation still happens, I’m pretty much at my wits’ end. Would really appreciate some help on this matter, thank you so much!
Relevant code:
<script>
(function() {
const button = document.getElementById('btn-all');
const content = document.getElementById('def-all');
window.toggleBtn = function() {
if (content.style.display === 'none') {
button.classList.add('expanded-button');
content.style.display = 'block';
content.scrollIntoView({
behavior: "smooth", //"auto"
block: "start",
inline: "nearest"
});
button.textContent = 'Hide all (P)';
} else { //hide content
button.classList.remove('expanded-button');
content.style.display = 'none';
button.textContent = 'Show all (P)';
}
}
button.addEventListener('click', function() {
toggleBtn()
});
addEventListener("keydown", (event) => {
if (event.key === "p") {
toggleBtn();
}
});
})()
</script>
Thanks and cheers.