jQuery: Get height of hidden element in jQuery

后端 未结 14 2447
南方客
南方客 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条回答
  •  礼貌的吻别
    2020-11-22 10:11

    If you've already displayed the element on the page previously, you can simply take the height directly from the DOM element (reachable in jQuery with .get(0)), since it is set even when the element is hidden:

    $('.hidden-element').get(0).height;
    

    same for the width:

    $('.hidden-element').get(0).width;
    

    (thanks to Skeets O'Reilly for correction)

提交回复
热议问题