0

I have open/close 'options' of 'select' on click anyone 'div' or 'button'. How this done by javaScript or JQuery. Thanks.

golsear
  • 55
  • 2
  • 9

3 Answers3

2

If what you're asking is how to cause a drop-down select to drop down programmatically (e.g., in response to a click somewhere else that triggers your code), you can't do that.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
  • You *can* cause a `select` to drop down using its `size` property. I've used it @ http://jsfiddle.net/KooiInc/8swnS/ – KooiInc Mar 26 '12 at 10:24
  • @KooiInc: That's not dropping down drop-down select, that's changing a drop-down select into a non-drop-down select, with all of the layout implications that, er, implies. :-) (You're then handling the layout implications in your code and styling, but that's not the same thing.) – T.J. Crowder Mar 26 '12 at 10:37
1

You can easily simulate a click on an element, but a click on a <select> won’t open up the dropdown.

$('div').bind('click', function() {
     // code for open and close your select
});

Here the reference Can I open a dropdownlist using jQuery

Community
  • 1
  • 1
antonjs
  • 14,060
  • 14
  • 65
  • 91
1

If you want to manipulate a <select> control, you can try using its size property. If its size is > 1, it will display options. Something along the lines of:

[somediv].onclick = function(){
  [someselect].size = 10;
}

Like T.J. Crowder rightfully remarked, this doesn't 'open' a dropdown, but it offers the possibility (using styling etc.) to simulate it.

KooiInc
  • 119,216
  • 31
  • 141
  • 177
  • 2
    That doesn't drop-down a drop-down select box, that turns a drop-down select box into a non-drop-down select box: http://jsbin.com/isikod Naturally you can play games with the styling and such, but to say that you can "open" it like that is misleading. – T.J. Crowder Mar 26 '12 at 10:35