1

I'm trying to get the height of my elements that contains class category. I wan't to use .each() function but it seems to return me the entire document. There's my code :

$('.category').each((index) => {
    console.log($(this).height());
});

This return me :

828 (the document height)..

Any idea ?

Jeremy M.
  • 1,154
  • 1
  • 9
  • 29

1 Answers1

3

That's because you are using an Arrow Function, which binds the this value of the enclosing context.

Use a regular Function.

$('.category').each(function(index) {
  console.log($(this).height());
});

I know they look cute and all that but they are not perfect replacements for regular Functions.

nicholaswmin
  • 21,686
  • 15
  • 91
  • 167