javascriptselector

change labels value with javascript, when no id or class


Can you help me for changing value with javascript, but code no have id or class here is code:

<label for="flights-origin-prepop-whitelabel_en">Origin</label>

I want change "Origin" with different word.

Some examples of my code:

<button role="flights_submit" type="submit">Search</button>
<div class="mewtwo-flights-destination">
<label for="flights-destination-prepop-whitelabel_en">Destination</label>
<input type="text" 
       name="destination_name" 
       autocomplete="off" required="" 
       id="flights-destination-prepop-whitelabel_en" 
       placeholder="Destination" 
       data-label="Destination" 
       role="flights-destination" 
       data-modal-modifier="whitelabel_en" 
       data-placeholder-initialized="true">

<input type="hidden" 
       name="destination_iata" 
       id="flights-destination-whitelabel_en" value="">
</div>

How can change this placeholder "Destination", and label text Destination?

Thanks


Solution

  • You can change the origin texto doing this:

    document.querySelector("label[for='flights-origin-prepop-whitelabel_en']").textContent = 'New Text';