JavaScript Toggle Function in WordPress Not Working on First Click
-
Hello everyone, I’m quite new to coding.
I’m having an issue with a toggle function on a WordPress page. I’m trying to make a hidden table visible when a button is clicked, but the function doesn’t work on the first click—it only works on the second click.
Here’s the JavaScript I’m using:ticketComparisonBtn.addEventListener('click', function() {
if (comparisonTable.style.display === 'none') {
comparisonTable.style.display = 'block';
} else {
comparisonTable.style.display = 'none';
}
});
The table is initially hidden via CSS with:.hidden {
display: none;
}
Does anyone have an idea why it wouldn’t toggle properly the first time and how I can fix this?
Thanks for the help!The page I need help with: [log in to see the link]
- You must be logged in to reply to this topic.