I have the following configuration:
var pageone = document.getElementById("pageone"),
pagetwo = document.getElementById("pagetwo"),
pagethree = document.getElementById("pagethree"),
bfpone = document.getElementById("buttonone"),
bfptwo = document.getElementById("buttontwo"),
bfpthree = document.getElementById("buttonthree");
$(pagetwo).hide();
$(pagethree).hide();
$(bfpone).click(function () {
$(pageone).show();
$(pagetwo).hide();
$(pagethree).hide();
});
$(bfptwo).click(function () {
$(pageone).hide();
$(pagetwo).show();
$(pagethree).hide();
});
$(bfpthree).click(function () {
$(pageone).hide();
$(pagetwo).hide();
$(pagethree).show();
});
.page{
background:red;
color:white;
margin:2em;
padding:1em;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="buttonone">Btn one</div>
<div id="buttontwo">Btn two</div>
<div id="buttonthree">Btn three</div>
<div id="pageone" class="page">Pageone</div>
<div id="pagetwo" class="page">Pagetwo</div>
<div id="pagethree" class="page">Pagethree</div>
Run codeHide resultWhen you click on a page-specific div, the selected page is displayed, and the rest are hidden.
It works fine, but I want the jQuery script to be more efficient when I add any number of pages, it works without the need to change (or at least it works without adding a lot of code). The only condition is that it should use only javascript and jQuery .
Thank.
source
share