Modify the opentab function to accept the event parameter:
function opentab(event, tabname) {
for (let tablink of tablinks) {
tablink.classList.remove("active-link");
}
for (let tabcontent of tabcontents) {
tabcontent.classList.remove("active-tab");
}
event.currentTarget.classList.add("active-link");
document.getElementById(tabname).classList.add("active-tab");
}
This seems to make it workable. Please let me know.