<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#song">Song</a></li>
<li id="image-tab"><a href="#image" data-toggle="tab">Image</a></li>
</ul>
<div class="tab-content">
<div id="image" class="tab-pane fade ">
<input class="btn btn-default btn-sm" type="file" name="userfile" id="image">
</div>
</div>
<div id="song" class="tab-pane fade in active">
<div class="form-group">
<input id="song-link" placeholder="Paste Soundcloud link here" type="text">
</div>
</div>
<div class="form-group">
<select class="form-control">
<option value="1">Music</option>
<option value="2">Photography</option>
<option value="3">Painting</option>
<option value="4">Fashion</option>
<option value="5">Modelling</option>
</select>
</div>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/js/bootstrap.min.js"></script>
I have to hide image tab when I select music and song tab when I click the rest. I have tried to use display none using CSS but it didn’t work.
4
Answers
You have just to add and remove bootstrap classes
fade in
andfade
.for example if you want to hide the song tab and show the image tab, you will have to do the following:
First give your select an id
Then get the selected value like this:
Finally, according to the selected value, hide and show your tabs:
Give some id or class to
<select class="form-control" id="my-select">
Give id or class to Song tab
then check for change event.
Add
ID
for yourselect
:Then you have to check the value of the selected option and hide the image tab when it is
music
by showing another tab (I expect that you want to change to song tab).I also made some minor changes in your HTML.
CODEPEN
Have a look at below approach:
We need to
hide()
the<a>
tag of Tab as well as need toremoveClass("in")
from corresponding tab content before showing the other tab.