I have been working on an app using electron, and I have a function that successfully adds tabs to the app. The issue arises when I try to add tabs via JavaScript with the onclick attribute - they show up as expected but do not execute the code to hide and show tab content like the manually added ones.
I believe that my function is adding everything necessary for proper execution, but I'm open to being proven wrong. Here's the function responsible for adding tabs and calling openTab() onclick, which works when done manually:
function addTab() {
const button = document.createElement("button");
button.className = "tab-link";
button.innerHTML = "New Tab";
button.onclick = "openTab(event,'test')";
document.getElementsByClassName("tab")[0].appendChild(button);
}
If it's helpful, here's the function used to hide and show tab content:
function openTab(evt, tabName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tab-content");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tab-link");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(tabName).style.display = "block";
evt.currentTarget.className += " active";
}