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 function. For example in link function of the directive I try to do:
function link(scope, element, attr) {
var height = element.height();
}
However, in my code I get "Error: element.height is not a function".
Am I missing the reference to some angular.js module/library or documentation is not up to date?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With