Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJs element.height() not a function

Tags:

angularjs

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?

like image 893
nikib3ro Avatar asked Feb 28 '14 18:02

nikib3ro


1 Answers

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.

like image 121
raddevon Avatar answered Oct 03 '22 20:10

raddevon