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
jquery html css
add a comment |
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
jquery html css
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
add a comment |
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
jquery html css
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
jquery html css
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
add a comment |
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
add a comment |
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>
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
add a comment |
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>
I try but it is not working, please give full example
– code7772
Nov 7 at 18:07
add a comment |
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>
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
add a comment |
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>
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
add a comment |
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>
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>
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
add a comment |
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
add a comment |
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>
I try but it is not working, please give full example
– code7772
Nov 7 at 18:07
add a comment |
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>
I try but it is not working, please give full example
– code7772
Nov 7 at 18:07
add a comment |
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>
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>
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
add a comment |
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
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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