views:

30

answers:

1

How can I gram the nested element "4"?

I tried

var nights = $("div.nights h5 div.num").val();

and

var nights = $("div.nights > h5 > div.num").val();

example

<div class="nights">
        <h5 class="biguns">
            <div class="num">4</div>
            Nights
        </h5>
</div>
+2  A: 

Use .text() here instead, like this:

$("div.nights h5 div.num").text()
//or this works too:
$("div.nights > h5 > div.num").text()
//or just
$("div.num").text();

You can test it here, as you can see above, your selector is flexible, use what works on your overall markup. .val() is for input type elements, e.g. <input>, <select>, <textarea>, <button>...to get the text inside of any other element, use .text() instead.

Nick Craver
ah, yes... i knew it was something so simple my brain was going to explode. thanks.
holden
@holden - welcome :)
Nick Craver