How to find and select option with select specific label with jQuery

2

With jQuery, how do I change the label of an option, not the value, example:

<select id="meuSelect">
    <option>[nao_selecionar_esse label]</option>
    <option>[SELECIONAR_esse label]</option>
    <option>[nao_selecionar_esse label]</option>
</select>
    
asked by anonymous 15.12.2017 / 12:29

2 answers

1

You can do this as follows:

$("select").find("option").html("SEU_TEXTO");

Or if in case you want this specific option you can do so

$("select").find("option[value=10]").html("SEU_TEXTO");
    
15.12.2017 / 12:40
1

Use text

$(document).ready(function(){
      $('select option:nth-child(2)').text('alterado').attr('selected', 'true');
    })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><selectid="meuSelect">
        <option value='10'>[ALTERAR_ESSE_LABEL]</option>
        <option value='10'>[ALTERAR_ESSE_LABEL]</option>
        <option value='10'>[ALTERAR_ESSE_LABEL]</option>
    </select>

Note: this nth-child in the selector is to get the first select , not affecting others if it has more than one.

    
15.12.2017 / 12:40