samedi 25 avril 2015

Get height of absolutely positioned element with jQuery


I have list element containing an image. The list element has fixed proportions and is relative positioned, image is absolutely positioned inside it.

<ul>
    <li>
        <img src="..."/>
    </li>
</ul>

My goal is to find height of both li and img with jQuery.

var li = $('li');
var image = li.find('img');
console.log("li height = " + li.outerHeight());
console.log("image height = " + image.height());

Unfortunately, this code gives me image height equal to 0 (Fiddle).
How can I get the correct img height?


Aucun commentaire:

Enregistrer un commentaire