Om Prakash
Om Prakash

Reputation: 1

How to get the height of div when height is set in CSS file?

The div is been generated at run time in js file. The height of the div is defined in class. Now I want to get the height of this div.

I have already tried :-

$('.maxHeight').height();
     $('.maxHeight').inner-height();
     $('.maxHeight').outer-height();
     $('.maxHeight').offset-height();
     $('.maxHeight').client-height();

Thanks

Upvotes: 0

Views: 59

Answers (2)

Nik Weiss
Nik Weiss

Reputation: 422

$('.maxHeight:eq(0)').css("height");

That should work. Make sure it is selecting your actual div, and not a different one that has the same class. Use the [0] if you have multiple instances

Upvotes: 1

Zorken17
Zorken17

Reputation: 1896

You need to wait for the DOM-three to finish before you can run you javascript.

Try to put you code in $(document).ready()

$(document).ready(function(){
  console.log($('.maxHeight').css("height"));
})

Upvotes: 1

Related Questions