I have two divs, one with display:none and the other with display:block.
When I click the button, I invert the div’s displays and call the window.reload method.
Unfortunately it updates but it is a blank page and does not come out of it. What am I doing wrong?
MY code JS :
function showHistorico(){
window.location.reload();
tabPrincipal.style.display="none";
tabHistorico.style.display="block";
}
My HTML
<button class="btn btn-sm btn-primary btn-block" id="btnHistorico" onclick="showHistorico()">HISTÓRICO</button>
<table class="table table-dark table-hover" id="tabPrincipal"> ... </table>
<table class="table table-dark table-hover" id="tabHistorico" style="display:none"> ... </table>
Unfortunately it updates but it is a blank page and does not come out of it. What am I doing wrong?
MY code JS :
function showHistorico(){
window.location.reload();
tabPrincipal.style.display="none";
tabHistorico.style.display="block";
}
My HTML
<button class="btn btn-sm btn-primary btn-block" id="btnHistorico" onclick="showHistorico()">HISTÓRICO</button>
<table class="table table-dark table-hover" id="tabPrincipal"> ... </table>
<table class="table table-dark table-hover" id="tabHistorico" style="display:none"> ... </table>
2
Answers
Define your variables first.
No need to reload the page, as I mentioned in the comments. If you reload then the rest of the code won’t execute.
All the explanations are given in comments. If you have any question feel free to ask.