Rachel S Rachel S - 4 months ago 25
Javascript Question

Hide a Bootstrap collapse trigger button after

I have a button to trigger a collapsed dive and open it. I would like to make the button disappear once it's been clicked.

Button:

<button id="show-more-home" data-toggle="collapse" data-target="#demo" class="btn btn-default"><i class="ion-chevron-down"></i> </button>


I tried this js but no go:

<script>
$("#show-more-home").addClass('hidden');
</script>

Answer

You can just use the jQuery .hide() function:

<script>
  $("body").on('click','#show-more-home', function(){ $(this).hide(); });
</script>

or if you have a .hidden class like:

.hidden {display:none !important;} 

you can also hide it like:

<script>
  $("body").on('click','#show-more-home',function(){ $(this).addClass('hidden'); });
</script>