Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I open a dropdownlist using jQuery

For this dropdownlist in HTML:

<select id="countries"> <option value="1">Country</option> </select> 

I would like to open the list (the same as left-clicking on it). Is this possible using JavaScript (or more specifically jQuery)?

like image 235
Jon Tackabury Avatar asked Dec 11 '08 18:12

Jon Tackabury


People also ask

How do I select a specific Dropdownlist using jQuery?

Syntax of jQuery Select Option$(“selector option: selected”); The jQuery select option is used to display selected content in the option tag. text syntax is below: var variableValue = $(“selector option: selected”).

How do I open a drop down menu?

Use any element to open the dropdown menu, e.g. a <button>, <a> or <p> element. Use a container element (like <div>) to create the dropdown menu and add the dropdown links inside it. Wrap a <div> element around the button and the <div> to position the dropdown menu correctly with CSS.

How to create dropdown JavaScript?

In pure JavaScript, you can use the document. createElement() method to programmatically create a dropdown list. Then you can call the Node's appendChild() method or jQuery's . append() method to append the dropdown list at the end of a container.


1 Answers

I was trying to find the same thing and got disappointed. I ended up changing the attribute size for the select box so it appears to open

$('#countries').attr('size',6); 

and then when you're finished

$('#countries').attr('size',1); 
like image 194
CommentLuv Avatar answered Oct 05 '22 01:10

CommentLuv