tags:

views:

46

answers:

2

the following code doesn't work in IE and Safari but works fine in firefox.

$('select#colors option').click(function() {
   //this is for testing but I get no alert in IE and Safari 
   alert('item selected');
}); 


<select id="colors" class="select">
     <option>Please select your style</option>
     <option>Navy</option>
     <option>Grey</option>
     <option>Black</option>
</select>

any ideas!!

+1  A: 

You need to attach the function to the select rather than each option:

$('select#colors').click(function() {
   alert('item selected: ' + $(this).val());
});
Greg
this way as soon as I click on it I get the alert, it doesn't allow me to choose something
amir
You need to either use the change() function instead of click, or watch for the value being changed in your click function
Greg
thanks, the change() function does the job.
amir
+1  A: 

Try this one instead

$('select#colors').bind('change', function() {
  alert('selected item changed');
});
jitter