Filter Element Option

1

How do I get the option object with Jquery specifically this:

$('#nome_responsavel').blur(function () {
   var id = $('option[value="'+$('#nome_responsavel').val()+'data-toggle=p"]').attr('id');
   alert(id);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script><label>Nome</label><inputtype="text" class="form-control" name="nome_responsavel" list="list_nome" id="nome_responsavel" required>
<datalist id="list_nome">
<option id="1" value="teste" data-toggle="p">teste</option>
<option id="2" value="teste2" data-toggle="p">teste2</option>
</datalist>
    
asked by anonymous 26.07.2016 / 20:17

1 answer

2

Use:

$('#list_nome option')  // Captura os dois options dentro do #list_nome

If you want to capture what has value equal to that of the text box is doing right, but only use one attribute in brackets, if you want two attributes, use two brackets:

$('#list_nome option[value="'+$('#nome_responsavel').val()+'"][data-toggle="p"]')  // Captura os dois options dentro do #list_nome
    
26.07.2016 / 20:28