rendered paste body $("div.filter_container a.haveonclick").click(function () { var name = $(this).attr('name'); var flag = 2; var foo = $("div.filter_container #"+name); //console.log(foo); if(foo.css("display") == "none") { foo.css({display: "block", visibility: "hidden"}) flag = 1 } else { foo.css({display: "none", visibility: "hidden"}) flag = 0 } var sizes = 0 var nsize = 0 $("div.filter_container .filters").each(function() { nsize = 0; $(this).children("ul").each(function(){ console.log("ID \"" + this.id + "\" | name \"" + name + "\""); if (this.style.display != "none" || this.id == name) { console.log(this.id + " Height: " + this.clientHeight + " Nsize = "+nsize) nsize += this.clientHeight } }) console.log("sizes: "+sizes+" | nsize: "+nsize+" | max result: "+Math.max(sizes,nsize)); console.log("-------------- GO TO ANOTHER .FILTERS ------------------") sizes = Math.max(sizes,nsize); }) $("div.filter_container .filters").css("height",sizes+10