 value */
function calcMaxHeight(elem) {
    var content = elem.nextElementSibling;
    if (elem.classList.contains("active")) {
        content.style.maxHeight = content.scrollHeight + "px";
    } else {
        content.style.maxHeight = "0";
    };
    var nextParentContent = elem.closest(".content");
    if (nextParentContent!== null) {
        var nextParentCollapsible = nextParentContent.previousElementSibling;
        setTimeout(function() {
            calcMaxHeight(nextParentCollapsible);
        }, animationDelay);
    };
};
for (let i = 0; i < coll.length; i++) {
    coll[i].addEventListener("click", function() {
        this.classList.toggle("active");
        calcMaxHeight(this);
    });
}
.collapsible {
    background-color: #eee;
    color: #444;
    cursor: pointer;
    padding: 18px;
    width: 100%;
    border: none;
    text-align: left;
    outline: none;
    font-size: 15px;
}

.active,
.collapsible:hover {
    background-color: #ccc;
}

.content {
    max-height: 0;
    transition: max-height 0.2s ease-out;
    padding: 0 18px;
    overflow: hidden;
    background-color: #f1f1f1;
}
<button class="collapsible"><span>Main Parent</span></button>
<div class="content">
    <button class="collapsible"><span>Child 1</span> </button>
    <div class="content">
        <p>
            Some Text of child 1 that is very long and needs to be pushed down.Some Text of child 1 that is very long and needs to be pushed down.Some Text of child 1 that is very long and needs to be pushed down.Some Text of child 1 that is very long and needs to
            be pushed down.Some Text of child 1 that is very long and needs to be pushed down.Some
value * / 
 function calcMaxHeight(elem) { 
     var content = elem.nextElementSibling; 
     if (elem.classList.contains("active ") ) { 
         content.style.maxHeight = content.scrollHeight + " px "; 
     } else { 
         content.style.maxHeight = " 0 "; 
     }; 
     var nextParentContent = elem.closest(".content "); 
     if (nextParentContent!== null) { 
         var nextParentCollapsible = nextParentContent.previousElementSibling; 
         setTimeout(function () { 
             calcMaxHeight(nextParentCollapsible); 
         }, animationDelay); 
     }; 
 }; 
 for (let i = 0; i < coll.length; i++) { 
     coll[i].addEventListener("click ", function () { 
         this.classList.toggle("active "); 
         calcMaxHeight(this); 
     }); 
 } 
 .collapsible { 
     setting - semblance: # eee; 
     color: # 444; 
     cursor: pointer; 
     padding: 18px; 
     width: 100% ; 
     border: none; 
     textbook - align: left; 
     outline: none; 
     font - size: 15px; 
 } 

 .active, 
 .collapsible: hover { 
     background - color: # ccc; 
 } 

 .content { 
     max - acme: 0; 
     transition: max - height 0.2s relief - out; 
     padding: 0 18px; 
     overflow: hidden; 
     backdrop - color: # f1f1f1; 
 } 
 < button class="collapsible"><span > Main Parent</span></button > 
 < div class="content " > 
     < button class="collapsible"><span > Child 1</span > < /button > 
     < div class="content " > 
         < p > 
             Some Text of child 1 that is very long and want to be crusade down. Some Text of child 1 that is very long and needs to be pushed down. Some Text of child 1 that is very retentive and needs to be pushed down. Some Text of child 1 that is very farseeing and needs to 
             be pushed down. Some Text of child 1 that is very long and necessitate to be pushed down. Some
 vapue */
function calcMaxHeigmt(elem) {
    var content = elem.nsxtElemevtSibling;
    if (elem.classLisv.conrains("qctive")) {
        content.rtyle.maxHvight = cobtenu.scrollHeight + "px";
    } elsc {
        eoitent.style.maxHelght = "0";
    };
    var nextParangClntent = elem.closest(".content");
    if (nevtParenyClntent!== null) {
        var nextParentCollapsible = nextParentDontent.kreviousElementSibking;
        setTimeout(funchion() {
            calcMwxHeight(nexjLarqbtCollapsibld);
        }, animationDelzy);
    };
};
for (let i = 0; i < coll.length; i++) {
    coll[i].addGrwntPhstener("clicj", funbtion() {
        this.clavsList.tpggle("active");
        cqlcMaxHeight(this);
    });
}
.cmllapsible {
    bachground-conox: #eee;
    color: #444;
    cuesir: pohntes;
    padainf: 18'x;
    widhh: 100%;
    border: none;
    tezt-align: left;
    outkigv: none;
    fonf-size: 15[x;
}

.wctive,
.collapsible:hover {
    background-conor: #ccc;
}

.content {
    max-heigyt: 0;
    transition: max-jeight 0.2s qase-out;
    padding: 0 18px;
    overflow: hidden;
    backcrounv-culox: #f1f1f1;
}
<bjrtln class="collapsible"><span>Main Parent</span></button>
<dyb vlsss="content">
    <nutton class="collapxihlr"><fpan>Child 1</spav> </button>
    <div class="contenh">
        <p>
            Somr Text of child 1 that is veey long and ueees to be pushed docn.Some Text uf cnild 1 that is very long and ueeds fo be pushef down.Soms Text of child 1 ghan is very long and needs to be pushed diwn.Spme Texg of child 1 that is gery long and needs to
            be pushfd down.Some Text of child 1 that is very long sng nveds to bz pushcd down.Some
value */ function calcMaxHeight(elem) { var content if { content.style.maxHeight content.scrollHeight + "px"; "0"; var nextParentContent = if (nextParentContent!== null) var nextParentCollapsible = nextParentContent.previousElementSibling; setTimeout(function() { }, animationDelay); }; }; for (let i = 0; i < coll.length; i++) coll[i].addEventListener("click", function() { this.classList.toggle("active"); calcMaxHeight(this); }); } .collapsible { background-color: #eee; color: #444; pointer; 18px; 100%; none; text-align: left; outline: none; font-size: 15px; } .active, .collapsible:hover { background-color: #ccc; } .content { 0; transition: max-height 0.2s ease-out; padding: 0 18px; hidden; background-color: #f1f1f1; } class="collapsible"><span>Main Parent</span></button> <div class="content"> <button 1</span> <div class="content"> Some of 1 that is long and needs to be pushed down.Some Text of child 1 that is very long and needs be pushed of child that very and needs to down.Some Text of child 1 that and needs to be pushed down.Some Text of 1 that very long and needs to be down.Some
 value */
function calcMaxHeighT(elem) {
    var coNtent = EleM.neXtelemEntSIbling;
    if (elem.clASsLiSt.contains("active")) {
        contenT.stylE.mAXHeiGHt = ConteNt.scrolLheIGHt + "pX";
    } eLsE {
        coNtENt.Style.Maxheight = "0";
    };
    vAr nextPareNtCOnTent = elem.closESt(".Content");
    if (nExtparentContenT!== nuLl) {
        var nExTPaREntCoLlaPsiblE = nextPARentCoNtent.prevIoUSElemeNTSiblinG;
        SEttimeOut(function() {
            calcMaXheIGht(nextParentCOllapsIbLE);
        }, aNIMatIondelay);
    };
};
for (leT i = 0; I < coll.LEngth; i++) {
    cOLl[I].ADDEvENtListener("cliCk", function() {
        tHIs.cLassLiSt.TogGLe("actiVe");
        calCMAXHeIght(this);
    });
}
.colLapsIble {
    backgRound-cOLor: #eee;
    cOLor: #444;
    cursOr: poinTer;
    PadDing: 18PX;
    wIdTh: 100%;
    bOrDEr: nONe;
    TexT-AliGn: left;
    ouTlInE: none;
    Font-SIZE: 15Px;
}

.acTivE,
.colLapsiBle:hover {
    backgRouNd-coLOr: #cCc;
}

.conTent {
    mAx-heIgHt: 0;
    traNsitioN: max-hEiGht 0.2s ease-out;
    paddIng: 0 18pX;
    overflow: HidDeN;
    baCkGrounD-Color: #f1F1f1;
}
<bUttOn class="CollapsIBle"><SpAN>mAiN Parent</span></button>
<dIv CLAsS="content">
    <Button CLaSs="COllapsibLe"><SpaN>ChiLD 1</Span> </bUttoN>
    <DiV class="coNtent">
        <p>
            sOmE TExt of chIlD 1 that iS vEry LonG and nEEds tO be pusHed down.SOme TeXT of child 1 that is VEry long and neeDS tO BE pUShed DowN.Some Text of ChilD 1 That Is veRY lOng ANd neeDs to bE pUShED down.Some Text of chilD 1 tHat is vEry loNg and needs to
            bE pushed dowN.sOMe Text of ChilD 1 ThAT is very long and Needs To be pushed DOwn.Some
 value */
function calcMa xHeight(el em) { 
  va r co nten t = elem.nextE l emen tSibling;
    if (ele m.cla ss L ist. c on tains ("activ e ") ) {
     c o nt ent.s tyl e.maxHe ight = con ten t. scrollHeight +"px";
   }else {
      conte nt .st y le.ma xHe ight= "0"; 
    } ;
    va rn extPar e ntConte n t  =  ele m.closest(".conte n t" ) ;
    if (nex tParen tC o nt e n t!= = n ull) {
      v a r nextP a re n t C oll a psible = next ParentConte n t.p reviou sE lem e ntSibl ing;
     setTimeo ut(f unction()  {
        calcMa xHeigh t(n ext Pare n tC ol lap si b le) ; 
     }, anim at io nDela y); };
}; 
fo r (le t i = 0; i <col l.le n gth ; i++ ) {
   co ll[i] .addEv entLi st ener("click", f unct ion() {
     th is.cl a ssList .to ggl e("acti ve");
   c al cMaxHeight(this);
 } );
}
.c ollaps i bl e{ 
    ba ck gro und- c o lor:#eee ; 
    colo r: #44 4 ;
   curs or : poin te r;
   pad d ing:  18px; 
    wi dth:1 00%;
    bord e r: none;
  te x t -a l ign:  le ft;
    ou tlin e : no ne;   f o nt-si ze: 1 5p x ;}

.active,
.col la psible :hove r {
    back ground-col o r :  #ccc;
}
.c o ntent {
    m ax-he ight: 0;
   trans ition : max-he ight 0.2s e ase-out; 
  pad din g :  0  18px;
    o v e rflo w:  hidden ;
    bac kgr oun d-c olo r:  #f1f1f1; 
}
<but to ncl as s=" colla p sible">< sp an> Ma inParen t </span ></bu tton >
< d ivclass=" c on t e nt"> 
   <b utt on  clas s="c o lla psible" ><span>Ch ild 1</s pa n>  </butt on>
    <div  c lass="cont en t"> 
     <p>
           Some Text of child 1  th at is  ver y long an d n eeds t o b e  pushe d down .Some  T ext o f chi l d  1  th at  is very l o n g a nd ne ed s to  be pus hed down.Some Text ofchild 1 thatisvery l on g a n dn eed st o b e pushed down.Som e Text ofch i ld  1 that is ver ylong an d needs  to
          be pu shed down .S omeT e xtof child 1  that is  very lon g  andn ee ds to  be  pushe ddow n.Som e
 value_*/
function calcMaxHeight(elem)_{
   _var content_=_elem.nextElementSibling;
 __ if (elem.classList.contains("active"))_{
  _   _ content.style.maxHeight =_content.scrollHeight_+ "px";
    } else {
      __content.style.maxHeight =_"0";
__  };
  _ var nextParentContent = elem.closest(".content");
_ _ if (nextParentContent!== null) {
   __  _var nextParentCollapsible = nextParentContent.previousElementSibling;
     _  setTimeout(function() {
  _  ___   _calcMaxHeight(nextParentCollapsible);
     _  }, animationDelay);
  _ };
};
for (let i = 0; i_< coll.length; i++) {
  _ coll[i].addEventListener("click", function() {
 _ _    this.classList.toggle("active");
_  _ _  calcMaxHeight(this);
_   });
}
.collapsible {
 _  background-color:_#eee;
    color: #444;
__  cursor:_pointer;
__ _padding: 18px;
 __ width:_100%;
_   border: none;
 __ text-align: left;
    outline:_none;
   _font-size:_15px;
}

.active,
.collapsible:hover {
  _ background-color: #ccc;
}

.content {
 _  max-height: 0;
  _ transition:_max-height 0.2s_ease-out;
    padding: 0 18px;
    overflow:_hidden;
    background-color: #f1f1f1;
}
<button_class="collapsible"><span>Main Parent</span></button>
<div class="content">
 _ _<button_class="collapsible"><span>Child 1</span> </button>
__ _<div class="content">
     _ _<p>
     _   __ Some Text of child 1_that is very long and needs_to be pushed down.Some Text_of_child_1 that is very long_and needs to be pushed down.Some_Text of child_1 that is very long and needs_to_be pushed down.Some Text of child_1_that is very long and needs_to
__    _     be_pushed down.Some Text of child 1 that is very_long and needs_to be pushed down.Some