ProllyGeek
ProllyGeek

Reputation: 15856

Retrieve Option data from Select

I have pulldown menu defined like this:

<select id="select_command" ><option data-syntax="blabla"></option></select>

How can I retrieve the data-syntax of the currently selected option upon clicking some button ?

Upvotes: 0

Views: 78

Answers (2)

Pranav C Balan
Pranav C Balan

Reputation: 115282

Try this,

$('.button').click(function(){
    var sel=$('option').filter(':selected').data('syntax');
    alert(sel);
});

Upvotes: 2

VisioN
VisioN

Reputation: 145478

$('#some_button').on('click', function() {
    var syntax = $('#select_command :selected').data('syntax');
    // ...
});

Upvotes: 3

Related Questions