0

Here is the issue, which one I am not able solve. In my page, I am having a select menu. Beside the select menu, one button. What I want is, when I click the button, the select menu will open. Here is the code which one I started.

$('#myButton').click(function () {

    $('#mySelect').bind('mousedown', function () {
        console.log('foo');
    });

    $('#mySelect').trigger('mousedown');
});

Here is the jsbin link. http://jsbin.com/Odeyocof/2/edit?html,js,output

Dhaval Marthak
  • 17,246
  • 6
  • 46
  • 68
naresh kumar
  • 2,165
  • 3
  • 19
  • 21
  • the answer is... [http://stackoverflow.com/questions/249192/how-can-you-programmatically-tell-an-html-select-to-drop-down-for-example-due](http://stackoverflow.com/questions/249192/how-can-you-programmatically-tell-an-html-select-to-drop-down-for-example-due) – Kirill Dec 24 '13 at 07:32

1 Answers1

0

There is no default method to open a select element in JavaScript. But There is a different way to accomplish this task :

$('#myButton').click(function(){
 $('#mySelect').show();
 $('#mySelect')[0].size=2;/* Choose a size that's perfect */
});
/* Hide Select Menu when user clicks an option */
$('#mySelect').live("click",function(){
 $('#mySelect').hide();
});

Source

Subin
  • 3,445
  • 1
  • 34
  • 63