Expand collapse grid and adjust to page width The Next CEO of Stack OverflowHow to align a <div> to the middle (horizontally/width) of the pageScroll to the top of the page using JavaScript/jQuery?Get the size of the screen, current web page and browser windowHow can I refresh a page with jQuery?CSS background image to fit width, height should auto-scale in proportionoffsetting an html anchor to adjust for fixed headerBootstrap: Collapse other sections when one is expandedbootstrap.js Accordion Collapse / Expandexpand/collapse all in jqueryExpand, collapse function with jquery

Does the Idaho Potato Commission associate potato skins with healthy eating?

Can this note be analyzed as a non-chord tone?

Is it correct to say moon starry nights?

Is it convenient to ask the journal's editor for two additional days to complete a review?

Can Sneak Attack be used when hitting with an improvised weapon?

TikZ: How to fill area with a special pattern?

Towers in the ocean; How deep can they be built?

Getting Stale Gas Out of a Gas Tank w/out Dropping the Tank

Would a grinding machine be a simple and workable propulsion system for an interplanetary spacecraft?

Expressing the idea of having a very busy time

What is the difference between "hamstring tendon" and "common hamstring tendon"?

Why don't programming languages automatically manage the synchronous/asynchronous problem?

Film where the government was corrupt with aliens, people sent to kill aliens are given rigged visors not showing the right aliens

What steps are necessary to read a Modern SSD in Medieval Europe?

Why is information "lost" when it got into a black hole?

Purpose of level-shifter with same in and out voltages

How to avoid supervisors with prejudiced views?

What was Carter Burke's job for "the company" in Aliens?

Scary film where a woman has vaginal teeth

Is it OK to decorate a log book cover?

Lucky Feat: How can "more than one creature spend a luck point to influence the outcome of a roll"?

Do scriptures give a method to recognize a truly self-realized person/jivanmukta?

A question about free fall, velocity, and the height of an object.

The Ultimate Number Sequence Puzzle



Expand collapse grid and adjust to page width



The Next CEO of Stack OverflowHow to align a <div> to the middle (horizontally/width) of the pageScroll to the top of the page using JavaScript/jQuery?Get the size of the screen, current web page and browser windowHow can I refresh a page with jQuery?CSS background image to fit width, height should auto-scale in proportionoffsetting an html anchor to adjust for fixed headerBootstrap: Collapse other sections when one is expandedbootstrap.js Accordion Collapse / Expandexpand/collapse all in jqueryExpand, collapse function with jquery










0















I have a Grid view which is divided horizontally. Having 3 buttons which will expand and collapse grids accordingly. But it is not adjusting to the width of the page. I mean when I hide each grids, it should occupy entire page. Also the buttons i need to place in top of each place as shown in image. Also button should change + and - (Expand collapse).



What I have is



enter image description here



What I need is



enter image description here



Grid is as below



<button class="btnShowHide1">First</button> 
<button class="btnShowHide2">Second</button>
<button class="btnShowHide3">Third</button>
<div class="row col-lg-12">
<div class="col-lg-3">
<h3>Section 1</h3>
</div>
<div class="col-lg-3">
<h3>Section 2</h3>
</div>
<div class="col-lg-3">
<h3>Section 3</h3>
</div>
<div class="col-lg-3">
<h3>Section 4</h3>
</div>
</div>


My detailed code is : Code










share|improve this question






















  • The areas are only going to take up the space you gave them, col-lg-3 or 1/4 of the row width. If you want them to take up more when one is hidden, adjust which col-lg-* class they have when one is hidden

    – Taplar
    Mar 8 at 17:39












  • Can you give a fiddle or codepen with updated code with + and - buttons?

    – user1365067
    Mar 8 at 17:42











  • Can use any two images (one for + and one for -) with 3 set of colors to identify 3 grids. It should go to left side when collapsed so color will identify which grid it corresponds to. please help

    – user1365067
    Mar 12 at 17:23
















0















I have a Grid view which is divided horizontally. Having 3 buttons which will expand and collapse grids accordingly. But it is not adjusting to the width of the page. I mean when I hide each grids, it should occupy entire page. Also the buttons i need to place in top of each place as shown in image. Also button should change + and - (Expand collapse).



What I have is



enter image description here



What I need is



enter image description here



Grid is as below



<button class="btnShowHide1">First</button> 
<button class="btnShowHide2">Second</button>
<button class="btnShowHide3">Third</button>
<div class="row col-lg-12">
<div class="col-lg-3">
<h3>Section 1</h3>
</div>
<div class="col-lg-3">
<h3>Section 2</h3>
</div>
<div class="col-lg-3">
<h3>Section 3</h3>
</div>
<div class="col-lg-3">
<h3>Section 4</h3>
</div>
</div>


My detailed code is : Code










share|improve this question






















  • The areas are only going to take up the space you gave them, col-lg-3 or 1/4 of the row width. If you want them to take up more when one is hidden, adjust which col-lg-* class they have when one is hidden

    – Taplar
    Mar 8 at 17:39












  • Can you give a fiddle or codepen with updated code with + and - buttons?

    – user1365067
    Mar 8 at 17:42











  • Can use any two images (one for + and one for -) with 3 set of colors to identify 3 grids. It should go to left side when collapsed so color will identify which grid it corresponds to. please help

    – user1365067
    Mar 12 at 17:23














0












0








0








I have a Grid view which is divided horizontally. Having 3 buttons which will expand and collapse grids accordingly. But it is not adjusting to the width of the page. I mean when I hide each grids, it should occupy entire page. Also the buttons i need to place in top of each place as shown in image. Also button should change + and - (Expand collapse).



What I have is



enter image description here



What I need is



enter image description here



Grid is as below



<button class="btnShowHide1">First</button> 
<button class="btnShowHide2">Second</button>
<button class="btnShowHide3">Third</button>
<div class="row col-lg-12">
<div class="col-lg-3">
<h3>Section 1</h3>
</div>
<div class="col-lg-3">
<h3>Section 2</h3>
</div>
<div class="col-lg-3">
<h3>Section 3</h3>
</div>
<div class="col-lg-3">
<h3>Section 4</h3>
</div>
</div>


My detailed code is : Code










share|improve this question














I have a Grid view which is divided horizontally. Having 3 buttons which will expand and collapse grids accordingly. But it is not adjusting to the width of the page. I mean when I hide each grids, it should occupy entire page. Also the buttons i need to place in top of each place as shown in image. Also button should change + and - (Expand collapse).



What I have is



enter image description here



What I need is



enter image description here



Grid is as below



<button class="btnShowHide1">First</button> 
<button class="btnShowHide2">Second</button>
<button class="btnShowHide3">Third</button>
<div class="row col-lg-12">
<div class="col-lg-3">
<h3>Section 1</h3>
</div>
<div class="col-lg-3">
<h3>Section 2</h3>
</div>
<div class="col-lg-3">
<h3>Section 3</h3>
</div>
<div class="col-lg-3">
<h3>Section 4</h3>
</div>
</div>


My detailed code is : Code







jquery css twitter-bootstrap






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 8 at 17:26









user1365067user1365067

308




308












  • The areas are only going to take up the space you gave them, col-lg-3 or 1/4 of the row width. If you want them to take up more when one is hidden, adjust which col-lg-* class they have when one is hidden

    – Taplar
    Mar 8 at 17:39












  • Can you give a fiddle or codepen with updated code with + and - buttons?

    – user1365067
    Mar 8 at 17:42











  • Can use any two images (one for + and one for -) with 3 set of colors to identify 3 grids. It should go to left side when collapsed so color will identify which grid it corresponds to. please help

    – user1365067
    Mar 12 at 17:23


















  • The areas are only going to take up the space you gave them, col-lg-3 or 1/4 of the row width. If you want them to take up more when one is hidden, adjust which col-lg-* class they have when one is hidden

    – Taplar
    Mar 8 at 17:39












  • Can you give a fiddle or codepen with updated code with + and - buttons?

    – user1365067
    Mar 8 at 17:42











  • Can use any two images (one for + and one for -) with 3 set of colors to identify 3 grids. It should go to left side when collapsed so color will identify which grid it corresponds to. please help

    – user1365067
    Mar 12 at 17:23

















The areas are only going to take up the space you gave them, col-lg-3 or 1/4 of the row width. If you want them to take up more when one is hidden, adjust which col-lg-* class they have when one is hidden

– Taplar
Mar 8 at 17:39






The areas are only going to take up the space you gave them, col-lg-3 or 1/4 of the row width. If you want them to take up more when one is hidden, adjust which col-lg-* class they have when one is hidden

– Taplar
Mar 8 at 17:39














Can you give a fiddle or codepen with updated code with + and - buttons?

– user1365067
Mar 8 at 17:42





Can you give a fiddle or codepen with updated code with + and - buttons?

– user1365067
Mar 8 at 17:42













Can use any two images (one for + and one for -) with 3 set of colors to identify 3 grids. It should go to left side when collapsed so color will identify which grid it corresponds to. please help

– user1365067
Mar 12 at 17:23






Can use any two images (one for + and one for -) with 3 set of colors to identify 3 grids. It should go to left side when collapsed so color will identify which grid it corresponds to. please help

– user1365067
Mar 12 at 17:23













2 Answers
2






active

oldest

votes


















1














I changed the classes to use xs for StackOverflow.



Essentially, you need to derive the class to put on the cells by the number of visible columns left.






$(document).ready(function() 
var $columns = $('.row > div');

$('.btnShowHide').on('click', function ()
var columnIndex = $(this).data('column');
var classToRemove = 'col-xs-'+ (12 / $columns.not('.hidden').length);

$columns.removeClass(classToRemove);
$columns.eq(columnIndex).toggleClass('hidden');
$columns.addClass('col-xs-'+ (12 / $columns.not('.hidden').length));
);
);

.hidden 
display: none;


.row div
border: 1px red solid;

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button class="btnShowHide" data-column="0">First</button>
<button class="btnShowHide" data-column="1">Second</button>
<button class="btnShowHide" data-column="2">Third</button>
<div class="row">
<div class="col-xs-3">
<h3>Column 1</h3>
</div>
<div class="col-xs-3">
<h3>Column 2</h3>
</div>
<div class="col-xs-3">
<h3>Column 3</h3>
</div>
<div class="col-xs-3">
<h3>Column 4</h3>
</div>
</div>








share|improve this answer























  • what about + and - buttons?

    – user1365067
    Mar 9 at 9:22











  • Not working. Clicked first button it hides first section if I click again it hide others also

    – user1365067
    Mar 11 at 4:29











  • I do not see that behavior in this runnable snippet. Repeated clicking of the first button only toggles the first section.

    – Taplar
    Mar 12 at 17:14











  • buddy that button behaviour is not there and need to be implemented. Your valuable suggestions are welcome.

    – user1365067
    Mar 12 at 17:21











  • imgur.com/43fHpYO Repeated clicking of the first button does not affect the other buttons in this snippet, at least in Firefox. If you are using another browser and seeing an issue, please share that information. @user1365067

    – Taplar
    Mar 13 at 17:01


















1














You can't just toggle col-lg-3 and col-lg-4. The items would also need to be 6 or 12 columns depending on the count. You need to count the number of visible classes and apply the appropriate class to all:



$(document).ready(function()
$('.btnShowHide1').on('click', function()
$('.row div:first-child').toggleClass('hidden');
updateClasses();
);
$('.btnShowHide2').on('click', function()
$('.row div:nth-child(2)').toggleClass('hidden');
updateClasses();
);
$('.btnShowHide3').on('click', function()
$('.row div:nth-child(3)').toggleClass('hidden');
updateClasses();
);
);

function updateClasses()
var visibleDivs = $('.row div').filter(function()
return !$(this).hasClass('hidden');
);
var colClass = 'col-lg-' + (12 / visibleDivs.length);
$(visibleDivs).attr('class', colClass);






share|improve this answer























  • what about + and - buttons?

    – user1365067
    Mar 9 at 9:22











  • I can't figure out from your drawing what those are supposed to do.

    – dave
    Mar 12 at 15:14











  • @ dave I mean each grid should be associated with 3 buttons with expand/collapse. Once collapsed button should move to left side to the down of the button placed there and once expand it should go back to previous position. hope you are clear.

    – user1365067
    Mar 12 at 17:14











  • Not clear at all. Maybe if I saw an attempted implementation of these +/- buttons I might be able to understand what you're trying to achieve. But they're missing entirely from your original code.

    – dave
    Mar 12 at 17:37











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',
autoActivateHeartbeat: false,
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%2f55068146%2fexpand-collapse-grid-and-adjust-to-page-width%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









1














I changed the classes to use xs for StackOverflow.



Essentially, you need to derive the class to put on the cells by the number of visible columns left.






$(document).ready(function() 
var $columns = $('.row > div');

$('.btnShowHide').on('click', function ()
var columnIndex = $(this).data('column');
var classToRemove = 'col-xs-'+ (12 / $columns.not('.hidden').length);

$columns.removeClass(classToRemove);
$columns.eq(columnIndex).toggleClass('hidden');
$columns.addClass('col-xs-'+ (12 / $columns.not('.hidden').length));
);
);

.hidden 
display: none;


.row div
border: 1px red solid;

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button class="btnShowHide" data-column="0">First</button>
<button class="btnShowHide" data-column="1">Second</button>
<button class="btnShowHide" data-column="2">Third</button>
<div class="row">
<div class="col-xs-3">
<h3>Column 1</h3>
</div>
<div class="col-xs-3">
<h3>Column 2</h3>
</div>
<div class="col-xs-3">
<h3>Column 3</h3>
</div>
<div class="col-xs-3">
<h3>Column 4</h3>
</div>
</div>








share|improve this answer























  • what about + and - buttons?

    – user1365067
    Mar 9 at 9:22











  • Not working. Clicked first button it hides first section if I click again it hide others also

    – user1365067
    Mar 11 at 4:29











  • I do not see that behavior in this runnable snippet. Repeated clicking of the first button only toggles the first section.

    – Taplar
    Mar 12 at 17:14











  • buddy that button behaviour is not there and need to be implemented. Your valuable suggestions are welcome.

    – user1365067
    Mar 12 at 17:21











  • imgur.com/43fHpYO Repeated clicking of the first button does not affect the other buttons in this snippet, at least in Firefox. If you are using another browser and seeing an issue, please share that information. @user1365067

    – Taplar
    Mar 13 at 17:01















1














I changed the classes to use xs for StackOverflow.



Essentially, you need to derive the class to put on the cells by the number of visible columns left.






$(document).ready(function() 
var $columns = $('.row > div');

$('.btnShowHide').on('click', function ()
var columnIndex = $(this).data('column');
var classToRemove = 'col-xs-'+ (12 / $columns.not('.hidden').length);

$columns.removeClass(classToRemove);
$columns.eq(columnIndex).toggleClass('hidden');
$columns.addClass('col-xs-'+ (12 / $columns.not('.hidden').length));
);
);

.hidden 
display: none;


.row div
border: 1px red solid;

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button class="btnShowHide" data-column="0">First</button>
<button class="btnShowHide" data-column="1">Second</button>
<button class="btnShowHide" data-column="2">Third</button>
<div class="row">
<div class="col-xs-3">
<h3>Column 1</h3>
</div>
<div class="col-xs-3">
<h3>Column 2</h3>
</div>
<div class="col-xs-3">
<h3>Column 3</h3>
</div>
<div class="col-xs-3">
<h3>Column 4</h3>
</div>
</div>








share|improve this answer























  • what about + and - buttons?

    – user1365067
    Mar 9 at 9:22











  • Not working. Clicked first button it hides first section if I click again it hide others also

    – user1365067
    Mar 11 at 4:29











  • I do not see that behavior in this runnable snippet. Repeated clicking of the first button only toggles the first section.

    – Taplar
    Mar 12 at 17:14











  • buddy that button behaviour is not there and need to be implemented. Your valuable suggestions are welcome.

    – user1365067
    Mar 12 at 17:21











  • imgur.com/43fHpYO Repeated clicking of the first button does not affect the other buttons in this snippet, at least in Firefox. If you are using another browser and seeing an issue, please share that information. @user1365067

    – Taplar
    Mar 13 at 17:01













1












1








1







I changed the classes to use xs for StackOverflow.



Essentially, you need to derive the class to put on the cells by the number of visible columns left.






$(document).ready(function() 
var $columns = $('.row > div');

$('.btnShowHide').on('click', function ()
var columnIndex = $(this).data('column');
var classToRemove = 'col-xs-'+ (12 / $columns.not('.hidden').length);

$columns.removeClass(classToRemove);
$columns.eq(columnIndex).toggleClass('hidden');
$columns.addClass('col-xs-'+ (12 / $columns.not('.hidden').length));
);
);

.hidden 
display: none;


.row div
border: 1px red solid;

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button class="btnShowHide" data-column="0">First</button>
<button class="btnShowHide" data-column="1">Second</button>
<button class="btnShowHide" data-column="2">Third</button>
<div class="row">
<div class="col-xs-3">
<h3>Column 1</h3>
</div>
<div class="col-xs-3">
<h3>Column 2</h3>
</div>
<div class="col-xs-3">
<h3>Column 3</h3>
</div>
<div class="col-xs-3">
<h3>Column 4</h3>
</div>
</div>








share|improve this answer













I changed the classes to use xs for StackOverflow.



Essentially, you need to derive the class to put on the cells by the number of visible columns left.






$(document).ready(function() 
var $columns = $('.row > div');

$('.btnShowHide').on('click', function ()
var columnIndex = $(this).data('column');
var classToRemove = 'col-xs-'+ (12 / $columns.not('.hidden').length);

$columns.removeClass(classToRemove);
$columns.eq(columnIndex).toggleClass('hidden');
$columns.addClass('col-xs-'+ (12 / $columns.not('.hidden').length));
);
);

.hidden 
display: none;


.row div
border: 1px red solid;

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button class="btnShowHide" data-column="0">First</button>
<button class="btnShowHide" data-column="1">Second</button>
<button class="btnShowHide" data-column="2">Third</button>
<div class="row">
<div class="col-xs-3">
<h3>Column 1</h3>
</div>
<div class="col-xs-3">
<h3>Column 2</h3>
</div>
<div class="col-xs-3">
<h3>Column 3</h3>
</div>
<div class="col-xs-3">
<h3>Column 4</h3>
</div>
</div>








$(document).ready(function() 
var $columns = $('.row > div');

$('.btnShowHide').on('click', function ()
var columnIndex = $(this).data('column');
var classToRemove = 'col-xs-'+ (12 / $columns.not('.hidden').length);

$columns.removeClass(classToRemove);
$columns.eq(columnIndex).toggleClass('hidden');
$columns.addClass('col-xs-'+ (12 / $columns.not('.hidden').length));
);
);

.hidden 
display: none;


.row div
border: 1px red solid;

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button class="btnShowHide" data-column="0">First</button>
<button class="btnShowHide" data-column="1">Second</button>
<button class="btnShowHide" data-column="2">Third</button>
<div class="row">
<div class="col-xs-3">
<h3>Column 1</h3>
</div>
<div class="col-xs-3">
<h3>Column 2</h3>
</div>
<div class="col-xs-3">
<h3>Column 3</h3>
</div>
<div class="col-xs-3">
<h3>Column 4</h3>
</div>
</div>





$(document).ready(function() 
var $columns = $('.row > div');

$('.btnShowHide').on('click', function ()
var columnIndex = $(this).data('column');
var classToRemove = 'col-xs-'+ (12 / $columns.not('.hidden').length);

$columns.removeClass(classToRemove);
$columns.eq(columnIndex).toggleClass('hidden');
$columns.addClass('col-xs-'+ (12 / $columns.not('.hidden').length));
);
);

.hidden 
display: none;


.row div
border: 1px red solid;

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button class="btnShowHide" data-column="0">First</button>
<button class="btnShowHide" data-column="1">Second</button>
<button class="btnShowHide" data-column="2">Third</button>
<div class="row">
<div class="col-xs-3">
<h3>Column 1</h3>
</div>
<div class="col-xs-3">
<h3>Column 2</h3>
</div>
<div class="col-xs-3">
<h3>Column 3</h3>
</div>
<div class="col-xs-3">
<h3>Column 4</h3>
</div>
</div>






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 8 at 17:52









TaplarTaplar

17.9k21529




17.9k21529












  • what about + and - buttons?

    – user1365067
    Mar 9 at 9:22











  • Not working. Clicked first button it hides first section if I click again it hide others also

    – user1365067
    Mar 11 at 4:29











  • I do not see that behavior in this runnable snippet. Repeated clicking of the first button only toggles the first section.

    – Taplar
    Mar 12 at 17:14











  • buddy that button behaviour is not there and need to be implemented. Your valuable suggestions are welcome.

    – user1365067
    Mar 12 at 17:21











  • imgur.com/43fHpYO Repeated clicking of the first button does not affect the other buttons in this snippet, at least in Firefox. If you are using another browser and seeing an issue, please share that information. @user1365067

    – Taplar
    Mar 13 at 17:01

















  • what about + and - buttons?

    – user1365067
    Mar 9 at 9:22











  • Not working. Clicked first button it hides first section if I click again it hide others also

    – user1365067
    Mar 11 at 4:29











  • I do not see that behavior in this runnable snippet. Repeated clicking of the first button only toggles the first section.

    – Taplar
    Mar 12 at 17:14











  • buddy that button behaviour is not there and need to be implemented. Your valuable suggestions are welcome.

    – user1365067
    Mar 12 at 17:21











  • imgur.com/43fHpYO Repeated clicking of the first button does not affect the other buttons in this snippet, at least in Firefox. If you are using another browser and seeing an issue, please share that information. @user1365067

    – Taplar
    Mar 13 at 17:01
















what about + and - buttons?

– user1365067
Mar 9 at 9:22





what about + and - buttons?

– user1365067
Mar 9 at 9:22













Not working. Clicked first button it hides first section if I click again it hide others also

– user1365067
Mar 11 at 4:29





Not working. Clicked first button it hides first section if I click again it hide others also

– user1365067
Mar 11 at 4:29













I do not see that behavior in this runnable snippet. Repeated clicking of the first button only toggles the first section.

– Taplar
Mar 12 at 17:14





I do not see that behavior in this runnable snippet. Repeated clicking of the first button only toggles the first section.

– Taplar
Mar 12 at 17:14













buddy that button behaviour is not there and need to be implemented. Your valuable suggestions are welcome.

– user1365067
Mar 12 at 17:21





buddy that button behaviour is not there and need to be implemented. Your valuable suggestions are welcome.

– user1365067
Mar 12 at 17:21













imgur.com/43fHpYO Repeated clicking of the first button does not affect the other buttons in this snippet, at least in Firefox. If you are using another browser and seeing an issue, please share that information. @user1365067

– Taplar
Mar 13 at 17:01





imgur.com/43fHpYO Repeated clicking of the first button does not affect the other buttons in this snippet, at least in Firefox. If you are using another browser and seeing an issue, please share that information. @user1365067

– Taplar
Mar 13 at 17:01













1














You can't just toggle col-lg-3 and col-lg-4. The items would also need to be 6 or 12 columns depending on the count. You need to count the number of visible classes and apply the appropriate class to all:



$(document).ready(function()
$('.btnShowHide1').on('click', function()
$('.row div:first-child').toggleClass('hidden');
updateClasses();
);
$('.btnShowHide2').on('click', function()
$('.row div:nth-child(2)').toggleClass('hidden');
updateClasses();
);
$('.btnShowHide3').on('click', function()
$('.row div:nth-child(3)').toggleClass('hidden');
updateClasses();
);
);

function updateClasses()
var visibleDivs = $('.row div').filter(function()
return !$(this).hasClass('hidden');
);
var colClass = 'col-lg-' + (12 / visibleDivs.length);
$(visibleDivs).attr('class', colClass);






share|improve this answer























  • what about + and - buttons?

    – user1365067
    Mar 9 at 9:22











  • I can't figure out from your drawing what those are supposed to do.

    – dave
    Mar 12 at 15:14











  • @ dave I mean each grid should be associated with 3 buttons with expand/collapse. Once collapsed button should move to left side to the down of the button placed there and once expand it should go back to previous position. hope you are clear.

    – user1365067
    Mar 12 at 17:14











  • Not clear at all. Maybe if I saw an attempted implementation of these +/- buttons I might be able to understand what you're trying to achieve. But they're missing entirely from your original code.

    – dave
    Mar 12 at 17:37















1














You can't just toggle col-lg-3 and col-lg-4. The items would also need to be 6 or 12 columns depending on the count. You need to count the number of visible classes and apply the appropriate class to all:



$(document).ready(function()
$('.btnShowHide1').on('click', function()
$('.row div:first-child').toggleClass('hidden');
updateClasses();
);
$('.btnShowHide2').on('click', function()
$('.row div:nth-child(2)').toggleClass('hidden');
updateClasses();
);
$('.btnShowHide3').on('click', function()
$('.row div:nth-child(3)').toggleClass('hidden');
updateClasses();
);
);

function updateClasses()
var visibleDivs = $('.row div').filter(function()
return !$(this).hasClass('hidden');
);
var colClass = 'col-lg-' + (12 / visibleDivs.length);
$(visibleDivs).attr('class', colClass);






share|improve this answer























  • what about + and - buttons?

    – user1365067
    Mar 9 at 9:22











  • I can't figure out from your drawing what those are supposed to do.

    – dave
    Mar 12 at 15:14











  • @ dave I mean each grid should be associated with 3 buttons with expand/collapse. Once collapsed button should move to left side to the down of the button placed there and once expand it should go back to previous position. hope you are clear.

    – user1365067
    Mar 12 at 17:14











  • Not clear at all. Maybe if I saw an attempted implementation of these +/- buttons I might be able to understand what you're trying to achieve. But they're missing entirely from your original code.

    – dave
    Mar 12 at 17:37













1












1








1







You can't just toggle col-lg-3 and col-lg-4. The items would also need to be 6 or 12 columns depending on the count. You need to count the number of visible classes and apply the appropriate class to all:



$(document).ready(function()
$('.btnShowHide1').on('click', function()
$('.row div:first-child').toggleClass('hidden');
updateClasses();
);
$('.btnShowHide2').on('click', function()
$('.row div:nth-child(2)').toggleClass('hidden');
updateClasses();
);
$('.btnShowHide3').on('click', function()
$('.row div:nth-child(3)').toggleClass('hidden');
updateClasses();
);
);

function updateClasses()
var visibleDivs = $('.row div').filter(function()
return !$(this).hasClass('hidden');
);
var colClass = 'col-lg-' + (12 / visibleDivs.length);
$(visibleDivs).attr('class', colClass);






share|improve this answer













You can't just toggle col-lg-3 and col-lg-4. The items would also need to be 6 or 12 columns depending on the count. You need to count the number of visible classes and apply the appropriate class to all:



$(document).ready(function()
$('.btnShowHide1').on('click', function()
$('.row div:first-child').toggleClass('hidden');
updateClasses();
);
$('.btnShowHide2').on('click', function()
$('.row div:nth-child(2)').toggleClass('hidden');
updateClasses();
);
$('.btnShowHide3').on('click', function()
$('.row div:nth-child(3)').toggleClass('hidden');
updateClasses();
);
);

function updateClasses()
var visibleDivs = $('.row div').filter(function()
return !$(this).hasClass('hidden');
);
var colClass = 'col-lg-' + (12 / visibleDivs.length);
$(visibleDivs).attr('class', colClass);







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 8 at 17:53









davedave

1,323526




1,323526












  • what about + and - buttons?

    – user1365067
    Mar 9 at 9:22











  • I can't figure out from your drawing what those are supposed to do.

    – dave
    Mar 12 at 15:14











  • @ dave I mean each grid should be associated with 3 buttons with expand/collapse. Once collapsed button should move to left side to the down of the button placed there and once expand it should go back to previous position. hope you are clear.

    – user1365067
    Mar 12 at 17:14











  • Not clear at all. Maybe if I saw an attempted implementation of these +/- buttons I might be able to understand what you're trying to achieve. But they're missing entirely from your original code.

    – dave
    Mar 12 at 17:37

















  • what about + and - buttons?

    – user1365067
    Mar 9 at 9:22











  • I can't figure out from your drawing what those are supposed to do.

    – dave
    Mar 12 at 15:14











  • @ dave I mean each grid should be associated with 3 buttons with expand/collapse. Once collapsed button should move to left side to the down of the button placed there and once expand it should go back to previous position. hope you are clear.

    – user1365067
    Mar 12 at 17:14











  • Not clear at all. Maybe if I saw an attempted implementation of these +/- buttons I might be able to understand what you're trying to achieve. But they're missing entirely from your original code.

    – dave
    Mar 12 at 17:37
















what about + and - buttons?

– user1365067
Mar 9 at 9:22





what about + and - buttons?

– user1365067
Mar 9 at 9:22













I can't figure out from your drawing what those are supposed to do.

– dave
Mar 12 at 15:14





I can't figure out from your drawing what those are supposed to do.

– dave
Mar 12 at 15:14













@ dave I mean each grid should be associated with 3 buttons with expand/collapse. Once collapsed button should move to left side to the down of the button placed there and once expand it should go back to previous position. hope you are clear.

– user1365067
Mar 12 at 17:14





@ dave I mean each grid should be associated with 3 buttons with expand/collapse. Once collapsed button should move to left side to the down of the button placed there and once expand it should go back to previous position. hope you are clear.

– user1365067
Mar 12 at 17:14













Not clear at all. Maybe if I saw an attempted implementation of these +/- buttons I might be able to understand what you're trying to achieve. But they're missing entirely from your original code.

– dave
Mar 12 at 17:37





Not clear at all. Maybe if I saw an attempted implementation of these +/- buttons I might be able to understand what you're trying to achieve. But they're missing entirely from your original code.

– dave
Mar 12 at 17:37

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55068146%2fexpand-collapse-grid-and-adjust-to-page-width%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







Popular posts from this blog

Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme