0
I wish that by clicking the button I could pull the value
and data-dado
of the selected option.
I tried with the code below, but it didn’t work:
$("#botaoexemplo").on("click", function() {
var valor = $('#exemplo').val();
var dado = $('#exemplo').attr(dado);
console.log(valor, dado);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select name='exemplo' id='exemplo' clas="exemplo">
<option value='1' class='teste' data-dado='a'>1</option>
<option value='2' class='teste' data-dado='b'>4</option>
<option value='3' class='teste' data-dado='c'>3</option>
<option value='4' class='teste' data-dado='d'>2</option>
</select>
<button id="botaoexemplo">Teste</button>