JQuery get height of each previous element

Posted by Jk_ on Stack Overflow See other posts from Stack Overflow or by Jk_
Published on 2012-04-11T22:09:23Z Indexed on 2012/04/11 23:29 UTC
Read the original article Hit count: 132

Filed under:
|

I'm trying to find a good solution to get the height of all the element above my target.

So loop the prev() function ! Any ideas on how I could deal with that ?

<div>
<div style="height:50px;width:100%"></div>
<div style="height:12px;width:100%"></div>
<div style="height:23px;width:100%"></div>
<div style="height:56px;width:100%"></div>
<div id="#mytarget"><p>HERE</p></div>
</div>

$('#mytarget').prev().each(function() {
    alert($(this).outerHeight());
});

and it will fires ["56","23","12","50"].

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about jquery-selectors