I'm having a problem in Chrome
with the following:
var items = $("option", obj);
items.each(function(){
$(this).click(function(){
// alert("test");
process($(this).html());
return false;
});
});
The click
event doesn't seem to fire in Chrome
, but works in Firefox
.
I wanna be able to click
on a option
element from a combo, if I do instead another kind of element, lets say <li>
it works fine. Any ideas? Thanks.
Workaround:
$('#select_id').on('change', (function() { $(this).children(':selected').trigger('click'); }));
I found that the following worked for me - instead on using on click, use on change e.g.:
The easy way to change the select, and update it is this.
another example:
another example:
Maybe one of the new jquery versions supports the click event on options. It worked for me:
UPDATE: A possible usecase could be the following: A user sends a html form and the values are inserted into a database. However one or more values are set by default and you flag this automated entries. You also show the user that his entry is generated automatically, but if he confirm the entry by clicking on the already selected option you change the flag in the database. A rare sue case, but possible...
We can achieve this other way despite of directly calling event with
<select>
.JS part:
HTML part:
I know that this code snippet works for recognizing an option click (at least in Chrome and FF). Furthermore, it works if the element wasn't there on DOM load. I usually use this when I input sections of inputs into a single select element and I don't want the section title to be clicked.