Keith D Kaiser
Keith D Kaiser

Reputation: 1036

How do I hide a bootstrap-select?

I need to hide a select statement for part of an web application. At one point in the code I say $("#select1").addClass("hidden"); to hide it. Until I decided to use bootstrap-select it worked fine. But since I added the class="selectpicker" it no longer hides when told to. I can see the 'hidden' has been added to the class statement using web inspector but the select is not actually hidden. How do I make this work?

Upvotes: 5

Views: 16319

Answers (2)

Udit
Udit

Reputation: 307

You can also try

  <select class="form-control selectpicker" id="your_id">
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
  </select>

and to hide or show use

$('#your_id').selectpicker('hide');
$('#your_id').selectpicker('show');

Upvotes: 5

Jared Chu
Jared Chu

Reputation: 2862

bootstrap-select convert your select tag to a list of buttons. You should hide or show its parent instead of itself to avoid css override. Example:

<div class="form-group" id="form-group-1">
  <label for="select1">Select list:</label>
  <select class="form-control selectpicker" id="select1">
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
  </select>
</div>

<button id="btn-hide">Hide select</button>
<button id="btn-show">Show select</button>

In this case we will hide or show #form-group-1 instead of #select1:

$("#btn-hide").click(function(){
  $("#form-group-1").hide();
});

$("#btn-show").click(function(){
  $("#form-group-1").show();
});

Please take a look at my JSFiddle.

Upvotes: 7

Related Questions