0

This code works in Firefox but not in Chrome. Alert is executed only in Firefox. Why? What am I doing wrong?

jQuery(document).ready(function($){
    $('#myselect option').on('click', function() { 
            var selectvalue= $(this).attr('value');
            alert(selectvalue);
            return false;
    });
});
Joe
  • 15,669
  • 4
  • 48
  • 83
Danteonline
  • 19
  • 2
  • 6

1 Answers1

5

You probably don't want to bind events to the options because the handling will be inconsistent - if someone uses the keyboard arrows to select their option, will the .click event fire?

You're probably better off just binding $('#myselect').on('change', function... which will catch any time the value is changed for any reason.

Joe
  • 15,669
  • 4
  • 48
  • 83