How make Show/Hide Div box by jquery?











up vote
-4
down vote

favorite












I have five class, witch is disabled by default with style display: none;



Also i have div box with have this class



<style>.box-1, .box-2, .box-3, .box-4, .box-5 { display: none;}</style>

<div class="box-1">Name1</div><div class="box-1">Age1</div>
<div class="box-2">Name2</div><div class="box-2">Age2</div>
<div class="box-3">Name3</div><div class="box-3">Age3</div>
<div class="box-4">Name4</div><div class="box-4">Age4</div>
<div class="box-5">Name5</div><div class="box-5">Age5</div>

<div class="button-show">show</div> <div class="button-hide">hide</div>


bottom i have show and hide button.



I want make that in first click on SHOW, i can see box-1, in second click box-2... then box-3 box-4 box-5 and click on HIDE disable box from last.



Example 1:



if i have see 1 2 3 4 5, it will hide on click 5 4 3 2 1



Example 2:



if i have see 1 2, it will hide on click 2 1.



P.S. I want that is used jquery.js?ver=1.12.4










share|improve this question




















  • 1




    api.jquery.com/click api.jquery.com/show api.jquery.com/hide api.jquery.com/filter
    – Taplar
    Nov 7 at 15:44












  • If you have a clear understanding of the steps you want to take, then it's only a question of which methods to use. Take some time to reference the api in regards to event handlers and dom manipulation methods
    – Taplar
    Nov 7 at 15:45






  • 1




    it is expected you at least attempt to do the code yourself - this is not a free code writing service
    – Pete
    Nov 7 at 15:47















up vote
-4
down vote

favorite












I have five class, witch is disabled by default with style display: none;



Also i have div box with have this class



<style>.box-1, .box-2, .box-3, .box-4, .box-5 { display: none;}</style>

<div class="box-1">Name1</div><div class="box-1">Age1</div>
<div class="box-2">Name2</div><div class="box-2">Age2</div>
<div class="box-3">Name3</div><div class="box-3">Age3</div>
<div class="box-4">Name4</div><div class="box-4">Age4</div>
<div class="box-5">Name5</div><div class="box-5">Age5</div>

<div class="button-show">show</div> <div class="button-hide">hide</div>


bottom i have show and hide button.



I want make that in first click on SHOW, i can see box-1, in second click box-2... then box-3 box-4 box-5 and click on HIDE disable box from last.



Example 1:



if i have see 1 2 3 4 5, it will hide on click 5 4 3 2 1



Example 2:



if i have see 1 2, it will hide on click 2 1.



P.S. I want that is used jquery.js?ver=1.12.4










share|improve this question




















  • 1




    api.jquery.com/click api.jquery.com/show api.jquery.com/hide api.jquery.com/filter
    – Taplar
    Nov 7 at 15:44












  • If you have a clear understanding of the steps you want to take, then it's only a question of which methods to use. Take some time to reference the api in regards to event handlers and dom manipulation methods
    – Taplar
    Nov 7 at 15:45






  • 1




    it is expected you at least attempt to do the code yourself - this is not a free code writing service
    – Pete
    Nov 7 at 15:47













up vote
-4
down vote

favorite









up vote
-4
down vote

favorite











I have five class, witch is disabled by default with style display: none;



Also i have div box with have this class



<style>.box-1, .box-2, .box-3, .box-4, .box-5 { display: none;}</style>

<div class="box-1">Name1</div><div class="box-1">Age1</div>
<div class="box-2">Name2</div><div class="box-2">Age2</div>
<div class="box-3">Name3</div><div class="box-3">Age3</div>
<div class="box-4">Name4</div><div class="box-4">Age4</div>
<div class="box-5">Name5</div><div class="box-5">Age5</div>

<div class="button-show">show</div> <div class="button-hide">hide</div>


bottom i have show and hide button.



I want make that in first click on SHOW, i can see box-1, in second click box-2... then box-3 box-4 box-5 and click on HIDE disable box from last.



Example 1:



if i have see 1 2 3 4 5, it will hide on click 5 4 3 2 1



Example 2:



if i have see 1 2, it will hide on click 2 1.



P.S. I want that is used jquery.js?ver=1.12.4










share|improve this question















I have five class, witch is disabled by default with style display: none;



Also i have div box with have this class



<style>.box-1, .box-2, .box-3, .box-4, .box-5 { display: none;}</style>

<div class="box-1">Name1</div><div class="box-1">Age1</div>
<div class="box-2">Name2</div><div class="box-2">Age2</div>
<div class="box-3">Name3</div><div class="box-3">Age3</div>
<div class="box-4">Name4</div><div class="box-4">Age4</div>
<div class="box-5">Name5</div><div class="box-5">Age5</div>

<div class="button-show">show</div> <div class="button-hide">hide</div>


bottom i have show and hide button.



I want make that in first click on SHOW, i can see box-1, in second click box-2... then box-3 box-4 box-5 and click on HIDE disable box from last.



Example 1:



if i have see 1 2 3 4 5, it will hide on click 5 4 3 2 1



Example 2:



if i have see 1 2, it will hide on click 2 1.



P.S. I want that is used jquery.js?ver=1.12.4







jquery html css






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 7 at 16:55









AndreaT

31118




31118










asked Nov 7 at 15:42









code7772

209




209








  • 1




    api.jquery.com/click api.jquery.com/show api.jquery.com/hide api.jquery.com/filter
    – Taplar
    Nov 7 at 15:44












  • If you have a clear understanding of the steps you want to take, then it's only a question of which methods to use. Take some time to reference the api in regards to event handlers and dom manipulation methods
    – Taplar
    Nov 7 at 15:45






  • 1




    it is expected you at least attempt to do the code yourself - this is not a free code writing service
    – Pete
    Nov 7 at 15:47














  • 1




    api.jquery.com/click api.jquery.com/show api.jquery.com/hide api.jquery.com/filter
    – Taplar
    Nov 7 at 15:44












  • If you have a clear understanding of the steps you want to take, then it's only a question of which methods to use. Take some time to reference the api in regards to event handlers and dom manipulation methods
    – Taplar
    Nov 7 at 15:45






  • 1




    it is expected you at least attempt to do the code yourself - this is not a free code writing service
    – Pete
    Nov 7 at 15:47








1




1




api.jquery.com/click api.jquery.com/show api.jquery.com/hide api.jquery.com/filter
– Taplar
Nov 7 at 15:44






api.jquery.com/click api.jquery.com/show api.jquery.com/hide api.jquery.com/filter
– Taplar
Nov 7 at 15:44














If you have a clear understanding of the steps you want to take, then it's only a question of which methods to use. Take some time to reference the api in regards to event handlers and dom manipulation methods
– Taplar
Nov 7 at 15:45




If you have a clear understanding of the steps you want to take, then it's only a question of which methods to use. Take some time to reference the api in regards to event handlers and dom manipulation methods
– Taplar
Nov 7 at 15:45




1




1




it is expected you at least attempt to do the code yourself - this is not a free code writing service
– Pete
Nov 7 at 15:47




it is expected you at least attempt to do the code yourself - this is not a free code writing service
– Pete
Nov 7 at 15:47












2 Answers
2






active

oldest

votes

















up vote
1
down vote













You need jquery click event and a counter that remember the current number.



The method will be like below:






$(document).ready(function(){
let counter = 0;
$(".button-show").on("click", function(){
counter++;
if(counter > $('[class*=box]').length/2){
counter = $('[class*=box]').length/2;
}
$(".box-"+counter).show();
});


$(".button-hide").on("click", function(){
$(".box-"+counter).hide();
counter--;
});
});

.box-1, .box-2, .box-3, .box-4, .box-5 { display: none;}

.button-show, .button-hide{
width:100px;
height:30px;
background-color:blue;
color:white;
text-align:center;
line-height:30px;
border-radius: 5px;
display:inline-block;
margin:10px;
cursor:pointer;
}

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<div class="button-show">show</div> <div class="button-hide">hide</div>
<div class="box-1">Name1</div><div class="box-1">Age1</div>
<div class="box-2">Name2</div><div class="box-2">Age2</div>
<div class="box-3">Name3</div><div class="box-3">Age3</div>
<div class="box-4">Name4</div><div class="box-4">Age4</div>
<div class="box-5">Name5</div><div class="box-5">Age5</div>








share|improve this answer























  • Hi, thank you for answer. Cna it work with jquery.js ver=1.12.4, not with jquery.min.js
    – code7772
    Nov 7 at 18:11










  • Yes, I have changed the Snippet to 1.12.4 version
    – Nimit Shah
    Nov 7 at 18:49


















up vote
0
down vote













I imagine that you could do something like this:



var count = 1;

function show() {
$(".box-"+count).show();
count++;
}

function hide() {
for(val = 4; val == 0; val--){
$(".box-"+val).hide();
}
}


HTML



<style>.box-1, .box-2, .box-3, .box-4, .box-5 { display: none;}</style>

<div class="box-1">Name1</div><div class="box-1">Age1</div>
<div class="box-2">Name2</div><div class="box-2">Age2</div>
<div class="box-3">Name3</div><div class="box-3">Age3</div>
<div class="box-4">Name4</div><div class="box-4">Age4</div>
<div class="box-5">Name5</div><div class="box-5">Age5</div>

<div class="button-show" onclick="show()">show</div> <div class="button-hide" onclick="hide()">hide</div>





share|improve this answer























  • I try but it is not working, please give full example
    – code7772
    Nov 7 at 18:07











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53192825%2fhow-make-show-hide-div-box-by-jquery%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote













You need jquery click event and a counter that remember the current number.



The method will be like below:






$(document).ready(function(){
let counter = 0;
$(".button-show").on("click", function(){
counter++;
if(counter > $('[class*=box]').length/2){
counter = $('[class*=box]').length/2;
}
$(".box-"+counter).show();
});


$(".button-hide").on("click", function(){
$(".box-"+counter).hide();
counter--;
});
});

.box-1, .box-2, .box-3, .box-4, .box-5 { display: none;}

.button-show, .button-hide{
width:100px;
height:30px;
background-color:blue;
color:white;
text-align:center;
line-height:30px;
border-radius: 5px;
display:inline-block;
margin:10px;
cursor:pointer;
}

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<div class="button-show">show</div> <div class="button-hide">hide</div>
<div class="box-1">Name1</div><div class="box-1">Age1</div>
<div class="box-2">Name2</div><div class="box-2">Age2</div>
<div class="box-3">Name3</div><div class="box-3">Age3</div>
<div class="box-4">Name4</div><div class="box-4">Age4</div>
<div class="box-5">Name5</div><div class="box-5">Age5</div>








share|improve this answer























  • Hi, thank you for answer. Cna it work with jquery.js ver=1.12.4, not with jquery.min.js
    – code7772
    Nov 7 at 18:11










  • Yes, I have changed the Snippet to 1.12.4 version
    – Nimit Shah
    Nov 7 at 18:49















up vote
1
down vote













You need jquery click event and a counter that remember the current number.



The method will be like below:






$(document).ready(function(){
let counter = 0;
$(".button-show").on("click", function(){
counter++;
if(counter > $('[class*=box]').length/2){
counter = $('[class*=box]').length/2;
}
$(".box-"+counter).show();
});


$(".button-hide").on("click", function(){
$(".box-"+counter).hide();
counter--;
});
});

.box-1, .box-2, .box-3, .box-4, .box-5 { display: none;}

.button-show, .button-hide{
width:100px;
height:30px;
background-color:blue;
color:white;
text-align:center;
line-height:30px;
border-radius: 5px;
display:inline-block;
margin:10px;
cursor:pointer;
}

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<div class="button-show">show</div> <div class="button-hide">hide</div>
<div class="box-1">Name1</div><div class="box-1">Age1</div>
<div class="box-2">Name2</div><div class="box-2">Age2</div>
<div class="box-3">Name3</div><div class="box-3">Age3</div>
<div class="box-4">Name4</div><div class="box-4">Age4</div>
<div class="box-5">Name5</div><div class="box-5">Age5</div>








share|improve this answer























  • Hi, thank you for answer. Cna it work with jquery.js ver=1.12.4, not with jquery.min.js
    – code7772
    Nov 7 at 18:11










  • Yes, I have changed the Snippet to 1.12.4 version
    – Nimit Shah
    Nov 7 at 18:49













up vote
1
down vote










up vote
1
down vote









You need jquery click event and a counter that remember the current number.



The method will be like below:






$(document).ready(function(){
let counter = 0;
$(".button-show").on("click", function(){
counter++;
if(counter > $('[class*=box]').length/2){
counter = $('[class*=box]').length/2;
}
$(".box-"+counter).show();
});


$(".button-hide").on("click", function(){
$(".box-"+counter).hide();
counter--;
});
});

.box-1, .box-2, .box-3, .box-4, .box-5 { display: none;}

.button-show, .button-hide{
width:100px;
height:30px;
background-color:blue;
color:white;
text-align:center;
line-height:30px;
border-radius: 5px;
display:inline-block;
margin:10px;
cursor:pointer;
}

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<div class="button-show">show</div> <div class="button-hide">hide</div>
<div class="box-1">Name1</div><div class="box-1">Age1</div>
<div class="box-2">Name2</div><div class="box-2">Age2</div>
<div class="box-3">Name3</div><div class="box-3">Age3</div>
<div class="box-4">Name4</div><div class="box-4">Age4</div>
<div class="box-5">Name5</div><div class="box-5">Age5</div>








share|improve this answer














You need jquery click event and a counter that remember the current number.



The method will be like below:






$(document).ready(function(){
let counter = 0;
$(".button-show").on("click", function(){
counter++;
if(counter > $('[class*=box]').length/2){
counter = $('[class*=box]').length/2;
}
$(".box-"+counter).show();
});


$(".button-hide").on("click", function(){
$(".box-"+counter).hide();
counter--;
});
});

.box-1, .box-2, .box-3, .box-4, .box-5 { display: none;}

.button-show, .button-hide{
width:100px;
height:30px;
background-color:blue;
color:white;
text-align:center;
line-height:30px;
border-radius: 5px;
display:inline-block;
margin:10px;
cursor:pointer;
}

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<div class="button-show">show</div> <div class="button-hide">hide</div>
<div class="box-1">Name1</div><div class="box-1">Age1</div>
<div class="box-2">Name2</div><div class="box-2">Age2</div>
<div class="box-3">Name3</div><div class="box-3">Age3</div>
<div class="box-4">Name4</div><div class="box-4">Age4</div>
<div class="box-5">Name5</div><div class="box-5">Age5</div>








$(document).ready(function(){
let counter = 0;
$(".button-show").on("click", function(){
counter++;
if(counter > $('[class*=box]').length/2){
counter = $('[class*=box]').length/2;
}
$(".box-"+counter).show();
});


$(".button-hide").on("click", function(){
$(".box-"+counter).hide();
counter--;
});
});

.box-1, .box-2, .box-3, .box-4, .box-5 { display: none;}

.button-show, .button-hide{
width:100px;
height:30px;
background-color:blue;
color:white;
text-align:center;
line-height:30px;
border-radius: 5px;
display:inline-block;
margin:10px;
cursor:pointer;
}

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<div class="button-show">show</div> <div class="button-hide">hide</div>
<div class="box-1">Name1</div><div class="box-1">Age1</div>
<div class="box-2">Name2</div><div class="box-2">Age2</div>
<div class="box-3">Name3</div><div class="box-3">Age3</div>
<div class="box-4">Name4</div><div class="box-4">Age4</div>
<div class="box-5">Name5</div><div class="box-5">Age5</div>





$(document).ready(function(){
let counter = 0;
$(".button-show").on("click", function(){
counter++;
if(counter > $('[class*=box]').length/2){
counter = $('[class*=box]').length/2;
}
$(".box-"+counter).show();
});


$(".button-hide").on("click", function(){
$(".box-"+counter).hide();
counter--;
});
});

.box-1, .box-2, .box-3, .box-4, .box-5 { display: none;}

.button-show, .button-hide{
width:100px;
height:30px;
background-color:blue;
color:white;
text-align:center;
line-height:30px;
border-radius: 5px;
display:inline-block;
margin:10px;
cursor:pointer;
}

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<div class="button-show">show</div> <div class="button-hide">hide</div>
<div class="box-1">Name1</div><div class="box-1">Age1</div>
<div class="box-2">Name2</div><div class="box-2">Age2</div>
<div class="box-3">Name3</div><div class="box-3">Age3</div>
<div class="box-4">Name4</div><div class="box-4">Age4</div>
<div class="box-5">Name5</div><div class="box-5">Age5</div>






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 7 at 18:48

























answered Nov 7 at 15:55









Nimit Shah

1,7391310




1,7391310












  • Hi, thank you for answer. Cna it work with jquery.js ver=1.12.4, not with jquery.min.js
    – code7772
    Nov 7 at 18:11










  • Yes, I have changed the Snippet to 1.12.4 version
    – Nimit Shah
    Nov 7 at 18:49


















  • Hi, thank you for answer. Cna it work with jquery.js ver=1.12.4, not with jquery.min.js
    – code7772
    Nov 7 at 18:11










  • Yes, I have changed the Snippet to 1.12.4 version
    – Nimit Shah
    Nov 7 at 18:49
















Hi, thank you for answer. Cna it work with jquery.js ver=1.12.4, not with jquery.min.js
– code7772
Nov 7 at 18:11




Hi, thank you for answer. Cna it work with jquery.js ver=1.12.4, not with jquery.min.js
– code7772
Nov 7 at 18:11












Yes, I have changed the Snippet to 1.12.4 version
– Nimit Shah
Nov 7 at 18:49




Yes, I have changed the Snippet to 1.12.4 version
– Nimit Shah
Nov 7 at 18:49












up vote
0
down vote













I imagine that you could do something like this:



var count = 1;

function show() {
$(".box-"+count).show();
count++;
}

function hide() {
for(val = 4; val == 0; val--){
$(".box-"+val).hide();
}
}


HTML



<style>.box-1, .box-2, .box-3, .box-4, .box-5 { display: none;}</style>

<div class="box-1">Name1</div><div class="box-1">Age1</div>
<div class="box-2">Name2</div><div class="box-2">Age2</div>
<div class="box-3">Name3</div><div class="box-3">Age3</div>
<div class="box-4">Name4</div><div class="box-4">Age4</div>
<div class="box-5">Name5</div><div class="box-5">Age5</div>

<div class="button-show" onclick="show()">show</div> <div class="button-hide" onclick="hide()">hide</div>





share|improve this answer























  • I try but it is not working, please give full example
    – code7772
    Nov 7 at 18:07















up vote
0
down vote













I imagine that you could do something like this:



var count = 1;

function show() {
$(".box-"+count).show();
count++;
}

function hide() {
for(val = 4; val == 0; val--){
$(".box-"+val).hide();
}
}


HTML



<style>.box-1, .box-2, .box-3, .box-4, .box-5 { display: none;}</style>

<div class="box-1">Name1</div><div class="box-1">Age1</div>
<div class="box-2">Name2</div><div class="box-2">Age2</div>
<div class="box-3">Name3</div><div class="box-3">Age3</div>
<div class="box-4">Name4</div><div class="box-4">Age4</div>
<div class="box-5">Name5</div><div class="box-5">Age5</div>

<div class="button-show" onclick="show()">show</div> <div class="button-hide" onclick="hide()">hide</div>





share|improve this answer























  • I try but it is not working, please give full example
    – code7772
    Nov 7 at 18:07













up vote
0
down vote










up vote
0
down vote









I imagine that you could do something like this:



var count = 1;

function show() {
$(".box-"+count).show();
count++;
}

function hide() {
for(val = 4; val == 0; val--){
$(".box-"+val).hide();
}
}


HTML



<style>.box-1, .box-2, .box-3, .box-4, .box-5 { display: none;}</style>

<div class="box-1">Name1</div><div class="box-1">Age1</div>
<div class="box-2">Name2</div><div class="box-2">Age2</div>
<div class="box-3">Name3</div><div class="box-3">Age3</div>
<div class="box-4">Name4</div><div class="box-4">Age4</div>
<div class="box-5">Name5</div><div class="box-5">Age5</div>

<div class="button-show" onclick="show()">show</div> <div class="button-hide" onclick="hide()">hide</div>





share|improve this answer














I imagine that you could do something like this:



var count = 1;

function show() {
$(".box-"+count).show();
count++;
}

function hide() {
for(val = 4; val == 0; val--){
$(".box-"+val).hide();
}
}


HTML



<style>.box-1, .box-2, .box-3, .box-4, .box-5 { display: none;}</style>

<div class="box-1">Name1</div><div class="box-1">Age1</div>
<div class="box-2">Name2</div><div class="box-2">Age2</div>
<div class="box-3">Name3</div><div class="box-3">Age3</div>
<div class="box-4">Name4</div><div class="box-4">Age4</div>
<div class="box-5">Name5</div><div class="box-5">Age5</div>

<div class="button-show" onclick="show()">show</div> <div class="button-hide" onclick="hide()">hide</div>






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 7 at 21:47

























answered Nov 7 at 16:00









Tanino

259




259












  • I try but it is not working, please give full example
    – code7772
    Nov 7 at 18:07


















  • I try but it is not working, please give full example
    – code7772
    Nov 7 at 18:07
















I try but it is not working, please give full example
– code7772
Nov 7 at 18:07




I try but it is not working, please give full example
– code7772
Nov 7 at 18:07


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53192825%2fhow-make-show-hide-div-box-by-jquery%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud

Zucchini