AngularJs element.height() not a function

前端 未结 2 1543
梦毁少年i
梦毁少年i 2020-12-19 00:22

I am trying to make a directive that would influence element width/height. Looking through examples I\'ve seen that you can get/set width/height by referencing appropriate f

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

    If you are not including jQuery angular substitutes its own smaller library, jqLite. jqLite does not have a height() function for DOM elements, so you will either need to write your own or use the full version of jQuery in your project.

    The limited jqLite api is here.

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

    Geoff Genz is correct that jqLite has no height() method or equivalent, but there is still a way to get the height of the selected element. Try this:

    var height = element[0].offsetHeight;
    

    element[0] returns the pure DOM element (without the jqLite wrapper) which has an offsetHeight property.

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