Get HTML Element Height without JQuery in AngularJS

前端 未结 2 743
无人共我
无人共我 2020-12-08 18:35

I\'m getting familiar with AngularJS. I\'m trying to be as \'pure\' as I can. For that reason, I\'m trying to avoid including jQuery. However, I\'m having a challenge gettin

相关标签:
2条回答
  • 2020-12-08 19:19

    It appears this is working correctly and gives the same result if you use:

    element.style.height
    

    Since no inline style or CSS height is set on the element a blank line is shown. Instead of relying on the style you can get the HTML elements height directly.

    console.log(element[0].offsetHeight);
    

    http://plnkr.co/edit/03YWwjBjYpid4fVmDxlM?p=preview

    How do I retrieve an HTML element's actual width and height?

    0 讨论(0)
  • 2020-12-08 19:21

    The small wrapper around element provided by angular allows you to ask for properties, so:

    element.prop('offsetHeight');
    

    Will just work fine, see: http://plnkr.co/edit/pFHySDo7hjEcMKCqGuiV?p=preview

    0 讨论(0)
提交回复
热议问题