0

I'm having problems in the browser chrome, I want the result of jquery is "javascript alert", in the mozilla browser no problem.

I use code in jsfiddle

$('#lang').on('click', 'option', function() {
      alert($(this).val());
 });

How to handle it ??

  • use the change event of select element, why do you want the click event on the element – Arun P Johny Sep 03 '15 at 03:41
  • http://jsfiddle.net/arunpjohny/nbj4LL2h/1/ – Arun P Johny Sep 03 '15 at 03:42
  • @ArunPJohny what if the OP want to alert if it click on the same option twice? change won't fire if the selected option is selected again. – fuyushimoya Sep 03 '15 at 03:43
  • remove 'option' from $('#lang'). Try in this pattern $('#lang').on('click', function(){ alert($(this).val()); }) It will invoke onclick function as soon as you click the dropdown. but it always better to use 'change' instead of click – Krishna Sep 03 '15 at 03:47
  • I want when click the same option still responds – Hikmah Tiar Sep 03 '15 at 03:49
  • @HikmahTiar In my memory it seems there's a similar topic, but unfortunately I just found [how to use onClick() or onSelect() on option tag in jsp page](http://stackoverflow.com/q/3487263/1737627), which says it may not be supported. Anyway, as you're using jquery, consider wrap it with [jQuery.selectmenu](https://jqueryui.com/selectmenu/) or selectable? [jQuery.selectmenu.selected](http://api.jqueryui.com/selectmenu/#event-select) may suit your needs? – fuyushimoya Sep 03 '15 at 03:57

0 Answers0