javascriptjquerycss

Get value nested within a number of classes


I am trying to get the value in the pickup-address class, but with little success. This is my code so far. What am I doing wrong?

JS

var pickupAddress = $('.timeline-item.active-item > .timeline-status > .pickup-address').val();
alert(pickupAddress);

HTML

<div class="timeline-item active-item" style="background-color: rgb(255, 255, 255);">
    <img src="https://s3.amazonaws.com/uifaces/faces/twitter/jsa/128.jpg" alt="" class="img-rounded profile">
    <div class="timeline-status" style="width: 185px;"><strong>Stephen
    </strong>
        <br><span class="pickup-address">Whaddon</span> — <span class="dropoff-address">Bancroft</span>
        <br><span class="timeline-substatus grey-status waypoints">Via Lathbury</span>
        <br><span class="timeline-substatus grey-status remaining-seats">3 places remaining</span>
    </div>
</div>

Solution

  • Use .text or .html instead of .val because pickup-address is not input field

    var pickupAddress = $('.timeline-item.active-item > .timeline-status > .pickup-address').text();
    

    Example