tags:

views:

59

answers:

2

Hi all,
I have a dropdown menu that is populated with key value pairs in php. Now I want to use JQuery to attach click handlers to each of those keys.

How do I print out a list of the contents in a drop down menu in JQuery?
(I know to get the current value of the menu as $(this).val()

I was thinking - maybe iterate through every child element and grab the val?

Thanks,
Michael

+2  A: 
$('select#idselect option').each(function() {
  $(this).click(function() {
      // do stuff
  });
});
Daniel Moura
Ah, using the 'option' to filter, thanks.
Michael
A: 

This uses the change event, which is more applicable to a select box.

$("#select_id").change(function() {
    // get the value
    var value = $(this).val();

    // do something
    alert(value); 
}
sixthgear