How can I grab 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>
Use
.text()here instead, like this: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.