dmegatool
dmegatool

Reputation: 175

Get the height of an item inside last container

This should be pretty simple but I can't make it work. I need the height of an item that is inside the last item with a class.

HTML like so:

    <div class="tag" >
        <div class="left"></div>
        <div class="right"></div>
    </div>
    <div class="tag">
        <div class="left"></div>
        <div class="right"></div>
    </div>
    <div class="tag">
        <div class="left" id="I need this height !"></div>
        <div class="right"></div>
    </div>
<div class="footer"></div>

JavaScript poor attempt:

lastLeftHeight = $('.tag').last().$('.left').height();

I know that doesn't work. It's just to show what I'm trying to get .tag items can vary so I can't target a number or an ID.

Upvotes: 0

Views: 80

Answers (3)

Stephen Rutstein
Stephen Rutstein

Reputation: 105

I would try some combination of using children(), filter(), and last() to get the height of a particular child div.

http://www.w3schools.com/jquery/jquery_traversing_filtering.asp

This explains a little more about traversing up and down the DOM using jQuery, and with examples that I would think would help.

Upvotes: 0

PhilVarg
PhilVarg

Reputation: 4821

you almost had it, but instead of using jquery methods, it can be accomplished with the proper query selector

$(.tag:last .left).height()

this will grab the last .tag element and find every child element with the class .left and return their heights

heres a fiddle demonstrating the selector in action:
http://jsfiddle.net/6e0s4jzj/

Upvotes: 1

kavetiraviteja
kavetiraviteja

Reputation: 2208

try this ..

lastLeftHeight=$('.tag:last > .left').height();

Upvotes: 2

Related Questions