Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open dropdown from javascript

I there ANY way in javascript that we could trigger a select element (dropdown list) to open (i.e. drop)?

After searching alot on the web, it seems the answer to this question is no, but I decided to give it a try on here as well.

I know there are some css tricks that you can set the opacity of your select to 0 and place it over other elements to receive click, but that is not useful in my case.

Also there are tons of js APIs that bring the same dropdown functionality to browsers but they are not good solutions for me because then on mobile browsers (where the OS has a totally different mobile-friendly popup for dropdowns) the functionality would be seriously poor.

[Note] I specifically need to do this in an android browser, in case there is a hack for this special case.

Thanks.

like image 412
Mo Valipour Avatar asked Mar 16 '26 06:03

Mo Valipour


1 Answers

You could assign a value to the size attribute. This causes the number of visible options to change. This simulates a "drop-down". Add position:relative to a container, and position:absolute to the select to prevent the element from pushing other elements away.

Demo: http://jsfiddle.net/HQwXj/

like image 159
Rob W Avatar answered Mar 17 '26 18:03

Rob W