2

Why doesn't the following code work?

$('select option').live('click', function(){
  alert('hello')
})

html:

<select class="ok">
<option>5</option>
</select>

EXAMPLE: http://jsfiddle.net/fQxj7/2/

beeglebug
  • 3,522
  • 1
  • 23
  • 39
Sheikhasa Mozali
  • 237
  • 1
  • 9
  • 16

1 Answers1

5

Do this instead:

$('select').change(function(){
    alert('hello');
});

If you need to know the selected value inside the event handler, then you can do this:

$('select').change(function() {
    var selectedOption = $(this).val();
});

http://jsfiddle.net/FishBasketGordo/2ABAh/

FishBasketGordo
  • 22,904
  • 4
  • 58
  • 91