Having an issue with my app that happens randomly the first time it is run (sometimes it works still). After a browser refresh, it solves the issue so I believe its a race condition. However, I am binding the event to document and it is also within document ready so I am out of ideas how to remedy it.
I have a series of tab buttons in the class .inactivetab that get generated during page load. On click, it should call methods.setTab which changes the class to .activetab and changes the page that is viewed. Usually all the buttons get the event properly and this works. Sometimes though, a few buttons (not all) do not work. This is the code snippet below:
$(document).ready(function(){
$(document).on('click', '.inactivetab', function () {
methods.setTab($(this).attr('id').replace('-ButtonId', ''));
});
})
And this snippet is what creates the buttons within the program (where module[] is an array of pages/tabs returned from the db forming the buttons) :
var.modules.forEach(module => {
tab_HTML += "<button id=\"" + module[1] + "-ButtonId\" type=\"button\" class=\"inactivetab\" style=\"display:block\">" + module[2] + "</button>";
})
I thought putting document ready and delegating the event to the document would be the fix needed here but still facing the issue when the app is first opened that not all the buttons work. Any other ideas would be a huge help.