I'm trying to have a select
box automatically pop open when the use hovers over it, as if they had clicked it. Is this possible?
I would think I could do this easily with jQuery...
$("#settings-select").mouseover(
function(){
$(this).trigger("click");
}
);
But that does nothing. Any ideas?
trigger only call the functions bound via one of the binding functions of jQuery.
There is no cross-browser way to open a select from javascript (it might be possible to call
this.click()
on some versions of IE but I can't test, and I'm sure there is no way on other browsers).It's been a while but there is a solution I don't see here, using
hover
to change the length ofselect
:http://codepen.io/anon/pen/avdavQ
And here's a pen where it's a bit more than the bare necessity and has some styling :
Demo
Unfortunately the method with Chosen - did not work for me.
But I thought I could make my own selector on jQuery.
HTML:
JS:
https://codepen.io/qwer643/pen/LebKpo
I finally got this to work! You need Chosen; as others have pointed out, you can't do this with a normal
select
because there are no events available to use. But this will pop open the menu when you mouseover theselect
and close it when you mouseout, which is the exact effect I wanted.HTML:
JS:
$("#dropdown").trigger("liszt:open");
is what opens the menu. There is no equivalentliszt:close
event to trigger when you want to close it (as far as I know), but triggering aclick
on it instead has the same effect.This is not possible. You can only implement your own select-box, or Chosen plugin, but this is bad for usability. Also think about
trigger('focus')
.