Zainul Abideen
Zainul Abideen

Reputation: 1

how to open select list by clicking a button in jQuery or Javascript

<body>
    <form>
        <select name="test" id="test">
            <option value="one">one</option>
            <option value="two">two</option>
        </select>
    </form>
    <button>Open Select Bar</button>
    <script src="script.js"></script>
</body>

This is my html codes and I want to open the select list by clicking on the button in jquery, and I am unable to understand that how can I achieve it . Someone suggest me the way to achieve it,

Upvotes: -1

Views: 1184

Answers (1)

4b0
4b0

Reputation: 22323

  1. First of all give some id or class to your button. (For example I give id on snippet.)
  2. Use select box attribute size to open your select list using option and length when button click.

$('#btnselect').click(function(e) {
  $('#test').attr('size', $('option').length);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select name="test" id="test">
  <option value="one">one</option>
  <option value="two">two</option>
</select>

<button id='btnselect'>Open Select Bar</button>

Upvotes: 0

Related Questions