1

I am trying to capture the value 'Lusaka' in the following HTML of the page using Javascript

<div class="flight-list-container" id="outbounds">

        <div data-wl-section="itineraryHeader" class="flight-list-section flight-list-header-container" id="outbounds-header-container">
            <div class="flight-info">
                <h2 class="translate wasTranslated" data-wl-translate="label.flc.itineraryHeader.departing">Outbound flight</h2>
                <div class="xchnge-section-dl">
                    <span class="translate xchnge-section-dt wasTranslated" data-wl-translate="label.flc.itineraryHeader.flyingFrom">From</span>
                    <span class="xchnge-section-dd"><span class="translate wasTranslated" data-wl-translate="City.LHR">London</span>, <span class="translate wasTranslated" data-wl-translate="Country.GB">United Kingdom</span> (LHR)</span>
                    <span class="translate xchnge-section-dt wasTranslated" data-wl-translate="label.flc.itineraryHeader.flyingTo">To</span>
                    <span class="xchnge-section-dd"><span class="translate wasTranslated" data-wl-translate="City.LUN">Lusaka</span>, <span class="translate wasTranslated" data-wl-translate="Country.ZM">Zambia</span> (LUN)</span>
                </div>
<p class="translate wasTranslated" data-wl-translate="label.flc.itineraryHeader.disclaimer">Lorem ipsum</p>            </div>
        </div>

using the following code but don't know how to distinguish between the class holding the FlyingFrom and the FlyingTo values

function() {

var destination = document.getElementById("outbounds-header-container").getElementsByClassName("translate wasTranslated")[1].innerText

return destination

}
Munali
  • 11
  • 2

1 Answers1

0

You can us jQuery and get the values by following code

$('.xchnge-section-dl > span.translate').each(function(){
  alert( $(this).text()); //text in the container
})

Hope this helps!!

Gandharv
  • 110
  • 6