[英]Changing the height of a div if a class exists inside another div
I want to increase the height of .custom-main-container1
when you click on #tblHideShow
, if the .collapsing
class exists inside the #collapsableTable
div.如果
.collapsing
类存在于#collapsableTable
div 中,我想在单击#tblHideShow
时增加.custom-main-container1
的高度。
$('#tblHideShow').click(function() { $('#collapsableTable').toggleClass('collapsing'); if ($('#collapsableTable').hasClass('collapsing')) { $(this).parent().siblings('.custom-main-container1').css("height", "calc(100% - 241px)"); } else { $(this).parent().siblings('.custom-main-container1').css("height", "calc(100% - 314px)"); } });
body, html { height: 100%; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="custom-main-container1"> div content here </div> <div class="xyz" id="collapsableTable"> div content here </div> <div> <a href="#" class="abc" id="tblHideShow">table collapse</a> </div>
If I understood right your problem the following codesnipped will work for you:如果我理解正确你的问题,下面的代码剪断对你有用:
$('#tblHideShow').click(function() { $('#collapsableTable').toggleClass('collapsing'); if ($('#collapsableTable').hasClass('collapsing')) { $(this).parent().siblings('.custom-main-container1').css("height", "200px"); }else { $(this).parent().siblings('.custom-main-container1').css("height", "100px"); } });
.custom-main-container1{ height:200px; background-color: #45b6fe; font-size: 35px; padding: 5%; border-radius: 5px; } .xyz{ background-color: #daf0ff; height:100px; font-size: 35px; padding-left: 5%; border-radius: 5px; } .collapsing{ display:none; } .class2>#class1{ text-align: center; color: blue; } body, html { height: 100%; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="custom-main-container1"> Changeable Hight div content here </div> <div class="xyz collapsing" id="collapsableTable"> Collapseable div content here </div> <div> <a href="#" class="abc" id="tblHideShow">table collapse</a> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.