jQuery: Get height of hidden element in jQuery

后端 未结 14 2368
南方客
南方客 2020-11-22 09:49

I need to get height of an element that is within a div that is hidden. Right now I show the div, get the height, and hide the parent div. This seems a bit silly. Is there a

14条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 10:09

    One workaround is to create a parent div outside the element you want to get the height of, apply a height of '0' and hide any overflow. Next, take the height of the child element and remove the overflow property of the parent.

    var height = $("#child").height();
    // Do something here
    $("#parent").append(height).removeClass("overflow-y-hidden");
    .overflow-y-hidden {
      height: 0px;
      overflow-y: hidden;
    }
    
    
    
    This is some content I would like to get the height of!

提交回复
热议问题